Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB.Clauses Where not work #4073

Closed
XiaoXiaoSN opened this issue Feb 9, 2021 · 3 comments
Closed

DB.Clauses Where not work #4073

XiaoXiaoSN opened this issue Feb 9, 2021 · 3 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@XiaoXiaoSN
Copy link

XiaoXiaoSN commented Feb 9, 2021

GORM Playground Link

go-gorm/playground#275

Description

DB.Clauses where not work

Postgres

except

INSERT INTO "users" ("created_at","updated_at","deleted_at","name","age","birthday","company_id","manager_id","active","id") 
VALUES ('2021-02-08 17:29:10.811','2021-02-08 17:29:10.811',NULL,'alice',18,NULL,NULL,NULL,false,1) 
ON CONFLICT ("id") DO  UPDATE SET "age"=20 WHERE "name" = 'bob'  RETURNING "id"

got

INSERT INTO "users" ("created_at","updated_at","deleted_at","name","age","birthday","company_id","manager_id","active","id") 
VALUES ('2021-02-08 17:29:10.811','2021-02-08 17:29:10.811',NULL,'alice',18,NULL,NULL,NULL,false,1) 
ON CONFLICT ("id") WHERE "name" = 'bob' DO UPDATE SET "age"=20 RETURNING "id"

mysql (update: MySQL doesn't support on duplicated with Where)

except

INSERT INTO `users` (`created_at`,`updated_at`,`deleted_at`,`name`,`age`,`birthday`,`company_id`,`manager_id`,`active`,`id`) 
VALUES ('2021-02-08 17:33:42.736','2021-02-08 17:33:42.736',NULL,'alice',18,NULL,NULL,NULL,false,1) 
ON DUPLICATE KEY UPDATE `age`=20 WHERE `name`='bob'

got

INSERT INTO `users` (`created_at`,`updated_at`,`deleted_at`,`name`,`age`,`birthday`,`company_id`,`manager_id`,`active`,`id`) 
VALUES ('2021-02-08 17:33:42.736','2021-02-08 17:33:42.736',NULL,'alice',18,NULL,NULL,NULL,false,1) 
ON DUPLICATE KEY UPDATE `age`=20
@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Feb 9, 2021
@jinzhu
Copy link
Member

jinzhu commented Feb 9, 2021

MySQL doesn't support on duplicated with Where

@jinzhu jinzhu closed this as completed Feb 9, 2021
@XiaoXiaoSN
Copy link
Author

But it is also incorrect in Postgres. I expect that WHERE statement is after UPDATE SET.

@jinzhu
Copy link
Member

jinzhu commented Feb 10, 2021

@XiaoXiaoSN Fixed this on latest master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

2 participants