Skip site navigation (1) Skip section navigation (2)

Re: Duplicate key value error

From: "Dickson S(dot) Guedes" <listas(at)guedesoft(dot)net>
To: "Itagaki Takahiro" <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>, "Vlad Arkhipov" <arhipov(at)dc(dot)baikal(dot)ru>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Duplicate key value error
Date: 2009-07-17 16:25:25
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Em Fri, 03 Apr 2009 04:23:10 -0300, Itagaki Takahiro  
<itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp> escreveu:
> Vlad Arkhipov <arhipov(at)dc(dot)baikal(dot)ru> wrote:
>> Is it possible to print which key value is duplicated when 'Duplicate
>> key value violates unique constraint' occurs? Foreign key violation
>> error reports such kind of information.
> I think it is not difficult from a technical standpoint.
> The attached patch adds DETAIL messages to duplicate key value error:
>     postgres=# INSERT INTO tbl(pk1, pk2) VALUES ('A', 1);
>     ERROR:  duplicate key value violates unique constraint "tbl_pkey"
>     DETAIL:  Key (pk1,pk2)=(A,1) already exists.
> If no objection, I'd like to submit the patch to the next commit-fest  
> (8.5).

Hi Takahiro, i'm the reviewer of your patch, and the following are my  
comments about it:

The patch was applied totalty clean to CVS HEAD and compiled in Ubuntu  
8.04, Ubuntu 8.10 and AIX 5.3, but failed in follow tests:


Would be good to modify the outputs to expect a new "DETAIL:" line.

Another comment is that the patch isn't in the standart context form, but  

About the feature, it work as expected when I've INSERTed in both single  
and compound-key or UPDATEd the key values to violates the constraint,  
also in concurrently transactions. As expected too, when i INSERT or  
UPDATE the key with a value thath overflow the 512 bytes i'm getting the  
output as follow:

guedes=# INSERT INTO test_dup_char_key VALUES (repeat('x',1024), 'qq');
ERROR:  duplicate key value violates unique constraint  
DETALHE:  Key (...)=(...) already exists.

I'm thinking if could be better to shows Key (my_key)=(...) instead Key  
(...)=(...) -- well, i don't know how much people uses a key with more  
512B  and how often it is to they don't know wich key it is, (just reading  
a log, for example) to we consider this important.

On the other hand there is a comment by Tom [1] about "to refactor this so  
it's not btree-specific, but could be used by other index AMs", so could  
be better trying to think about this in a way to find another alternative,  
if it is possible.


Thanks for your patch!

Dickson S. Guedes

In response to


pgsql-hackers by date

Next:From: Petr JelinekDate: 2009-07-17 16:44:12
Subject: Re: [PATCH] DefaultACLs
Previous:From: Kevin GrittnerDate: 2009-07-17 16:00:03
Subject: Re: slow count in window query

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group