我在PostgreSQL 9.3.2上运行此查询。任何人都可以告诉我为什么这个查询在我不更新唯一列时会抛出唯一的违规异常。
内容表也有两个触发器,但它只是插入并更新其他表。
Execute command failed: ERROR: duplicate key value violates unique constraint "contents_0_uk"
DETAIL: Key (hash)=(\x145806e0794729ba98f16e4e8ec723cb) already exists.
CONTEXT: SQL statement "UPDATE contents cont
SET content = tmp.content,
primitive = tmp.primitive,
lang = ARRAY[lang_id(tmp.lang[1]), lang_id(tmp.lang[2]), lang_id(tmp.lang[3])],
percent = tmp.percent,
score = tmp.score
FROM tmp_post_bulk tmp
WHERE tmp.cid = cont.id
AND tmp.chash_matched = TRUE
AND (
cont.content != tmp.content
OR cont.primitive != tmp.primitive
OR cont.percent != tmp.percent
OR cont.score != tmp.score
OR cont.lang != ARRAY[lang_id(tmp.lang[1]), lang_id(tmp.lang[2]), lang_id(tmp.lang[3])]
)"
PL/pgSQL function content_bulk() line 53 at SQL statement
! Query is: SELECT content_bulk();
答案 0 :(得分:1)
由于此表中存在重复行(唯一列重复),因此当查询更新重复行时,PostgreSQL会抛出异常。
我将手动删除重复的行。