Why not support "For Update" in postgres? #2345

Open
opened 2023-10-22 07:56:59 +00:00 by demachitse · 7 comments
	results := []db_model.DummyTableA{}
	cond := builder.NewCond()
	cond = cond.Or(builder.Eq{"id": "xid000000000000000a1"})
	err := session.ForUpdate().Where(cond).Find(&results)
	if err != nil {
		log.Fatalf("failed to find dummy_table_a: %v", err)
	}

It doesn't work with postgres and returns error "only support mysql for update".

if statement.dialect.URI().DBType != schemas.MYSQL {
return errors.New("only support mysql for update")
}

Why not support "For Update" in postgres?
PostgreSQL supports "For Update".
I wonder it.

If there is another way, tell me please.

```golang results := []db_model.DummyTableA{} cond := builder.NewCond() cond = cond.Or(builder.Eq{"id": "xid000000000000000a1"}) err := session.ForUpdate().Where(cond).Find(&results) if err != nil { log.Fatalf("failed to find dummy_table_a: %v", err) } ``` It doesn't work with postgres and returns error "only support mysql for update". https://gitea.com/xorm/xorm/src/commit/dbe499091a7eacb01d06f9a20ff00c1384df797d/internal/statements/query.go#L287-L289 Why not support "For Update" in postgres? PostgreSQL supports "For Update". I wonder it. If there is another way, tell me please.
Owner

I don't know how to support it. If you know, please send a PR with make for update test enable for postgres.

I don't know how to support it. If you know, please send a PR with make for update test enable for postgres.
Author

Thank you for your response.

I changed code from

if statement.dialect.URI().DBType != schemas.MYSQL {
return errors.New("only support mysql for update")
}

to

	if !(statement.dialect.URI().DBType == schemas.MYSQL || statement.dialect.URI().DBType == schemas.POSTGRES) {
		return errors.New("only support mysql abd postgres for update")
	}

in local files.

And I tried to use ForUpdate().
It worked with postgres.

I will make PR.

Thank you for your response. I changed code from https://gitea.com/xorm/xorm/src/commit/dbe499091a7eacb01d06f9a20ff00c1384df797d/internal/statements/query.go#L287-L289 to ```golang if !(statement.dialect.URI().DBType == schemas.MYSQL || statement.dialect.URI().DBType == schemas.POSTGRES) { return errors.New("only support mysql abd postgres for update") } ``` in local files. And I tried to use `ForUpdate()`. It worked with postgres. I will make PR.
Author
@lunny https://gitea.com/demachitse/xorm/pulls/1#issuecomment-752561
Owner

Please send to the main repository.

Please send to the main repository.
Author

@lunny
I don't have permission to main repository.

remote: Gitea: User permission denied for writing.
To gitea.com:xorm/xorm.git

So, I forked main repository and fixed in forked repository.
demachitse/xorm#1

I tried merge to main repository from forked repository, but I don't know how to it.
For Gihub.com the GUI for merging into the base repository exists in the PR page creation.
But Gitea.com doesn't exists it.
That already tell you.
demachitse/xorm#1 (comment)

@lunny I don't have permission to main repository. ```shell remote: Gitea: User permission denied for writing. To gitea.com:xorm/xorm.git ``` So, I forked main repository and fixed in forked repository. https://gitea.com/demachitse/xorm/pulls/1 I tried merge to main repository from forked repository, but I don't know how to it. For Gihub.com the GUI for merging into the base repository exists in the PR page creation. But Gitea.com doesn't exists it. That already tell you. https://gitea.com/demachitse/xorm/pulls/1#issuecomment-752561
Owner

Looks like old cockroachdb doesn't support for update yet but new cockroachdb has other problems.

Looks like old cockroachdb doesn't support for update yet but new cockroachdb has other problems.
Contributor

Looks like old cockroachdb doesn't support for update yet but new cockroachdb has other problems.

Could you please explain what the specific problem is? I also have this requirement and urgently need to resolve it.

> Looks like old cockroachdb doesn't support for update yet but new cockroachdb has other problems. Could you please explain what the specific problem is? I also have this requirement and urgently need to resolve it.
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#2345
No description provided.