0

I run this query bellow on PostgreSQL 9.3.2. Can anyone tell me why this query bellow throw unique violation exception while I do not update the unique column.

The contents table also have two trigger but it just insert and update other table.

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();
4
  • Maybe the contents_0_uk constraint is on the tables updated by the triggers? Can you post the definition of the table? Commented Mar 12, 2014 at 10:03
  • contents_0_uk is on contents_0 which is a partition of contents table. Trigger do not update any partition in contents table and the updated table do not have any trigger. Commented Mar 12, 2014 at 10:07
  • Well, double check the triggers. Something is altering the hash column behind your back. Is that column part of the contents table? Commented Mar 12, 2014 at 10:26
  • contents_0 table inherit the contents table Commented Mar 12, 2014 at 10:34

1 Answer 1

1

I have just find out the problem is the same as Postgres, duplicate unique index

Because there are duplicateds row in this table (unique column duplicated), so when the query update the duplicated rows, PostgreSQL throw exception.

I will manual remove the duplicated rows.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.