Here is a small patch that changes the error message

    duplicate key value violates unique constraint "%s"

into

    duplicate key value violates primary key "%s"

when the constraint is in fact a primary key.

Comments?


PS: Yes, this would need a handful of regression test updates if
accepted.
Index: src/backend/access/nbtree/nbtinsert.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v
retrieving revision 1.176
diff -u -3 -p -r1.176 nbtinsert.c
--- src/backend/access/nbtree/nbtinsert.c	2 Jan 2010 16:57:35 -0000	1.176
+++ src/backend/access/nbtree/nbtinsert.c	20 Jan 2010 22:56:55 -0000
@@ -381,8 +381,11 @@ _bt_check_unique(Relation rel, IndexTupl
 										   values, isnull);
 						ereport(ERROR,
 								(errcode(ERRCODE_UNIQUE_VIOLATION),
-								 errmsg("duplicate key value violates unique constraint \"%s\"",
-										RelationGetRelationName(rel)),
+								 (rel->rd_index->indisprimary
+								  ? errmsg("duplicate key value violates primary key \"%s\"",
+										   RelationGetRelationName(rel))
+								  : errmsg("duplicate key value violates unique constraint \"%s\"",
+										   RelationGetRelationName(rel))),
 								 errdetail("Key %s already exists.",
 										   BuildIndexValueDescription(rel,
 															values, isnull))));
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to