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