Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 子句.OnConflict()不';在UPSERT期间不生成where条件_Postgresql_Go_Go Gorm - Fatal编程技术网

Postgresql 子句.OnConflict()不';在UPSERT期间不生成where条件

Postgresql 子句.OnConflict()不';在UPSERT期间不生成where条件,postgresql,go,go-gorm,Postgresql,Go,Go Gorm,我正在使用golang和gorm,并在Postgres上运行,需要进行一次升级。感谢您的帮助 我将插入一个“attributes”表,在“id”冲突时,只有当“organization_id”与给定值匹配时,才应更新该行 基于 及 上面的代码生成以下SQL,不带WHERE子句: INSERT INTO "attributes" ("organization_id","name","id") VALUES (2,&q

我正在使用golang和gorm,并在Postgres上运行,需要进行一次升级。感谢您的帮助

我将插入一个“attributes”表,在“id”冲突时,只有当“organization_id”与给定值匹配时,才应更新该行

基于 及

上面的代码生成以下SQL,不带WHERE子句:

INSERT INTO "attributes" ("organization_id","name","id") 
VALUES (2,"demo",15)
ON CONFLICT ("id") DO UPDATE SET "organization_id"="excluded"."organization_id", "name"="excluded"."name",
RETURNING "id"
应为包含WHERE子句的SQL:

INSERT INTO "attributes" ("organization_id","name","id") 
VALUES (2,"demo",15)
ON CONFLICT ("id") DO UPDATE SET "organization_id"="excluded"."organization_id", "name"="excluded"."name",
WHERE attributes.organization_id=2 
RETURNING "id"
修好了。首先,升级到gorm的最新版本。第二,删除这一行
Columns:[]子句
INSERT INTO "attributes" ("organization_id","name","id") 
VALUES (2,"demo",15)
ON CONFLICT ("id") DO UPDATE SET "organization_id"="excluded"."organization_id", "name"="excluded"."name",
WHERE attributes.organization_id=2 
RETURNING "id"