0
我有以下查询:独特contraint违反更新的声明
UPDATE "PostsTags"
SET "TagId" = "PostsTags"."TagId" #tgs."mainId"
FROM (
SELECT t1."TagId" AS "mainId", t1.text AS "mainText", t2."TagId" AS "malformedId", t2.text AS "malformedText"
FROM "TagTranslations" t1
INNER JOIN "TagTranslations" t2 ON t1.text = regexp_replace(t2.text, '^\s+','') AND t2.id != t1.id
WHERE regexp_replace(t1.text, '^\s+','') = t1.text AND t1."language" = 'en-us'
) tgs
WHERE "PostsTags"."TagId" = tgs."malformedId" AND "PostsTags"."language" = 'en-us' AND "PostsTags"."PostId" = 281
RETURNING *
正如你可以看到我更新TagId = TagId
(我设置相同的值,标签识别列)。我得到以下错误:
ERROR: duplicate key value violates unique constraint "PostsTags_pkey"
DETAIL: Key (language, "PostId", "TagId")=(en-us, 281, 10157) already exists.
有人可以告诉我如何可能我收到这种违规行为,而我实际上没有改变任何东西吗?
那是什么位“#tgs ......”在干什么? 'SET'TagId“=”TagId“#tgs。”mainId“' – 2014-09-20 16:03:32
您正在使用子查询中的值更新'TagId'。所以这肯定会造成重复。 – Wolph 2014-09-20 18:22:40
'#tgs。“mainId”'只是评论。我只是将TagId设置为其以前的值,以便如何导致违规? – user606521 2014-09-20 22:25:55