mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Improve unique-constraint-violation error messages to include the exact
values being complained of. In passing, also remove the arbitrary length limitation in the similar error detail message for foreign key violations. Itagaki Takahiro
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.171 2009/07/29 20:56:18 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.172 2009/08/01 19:59:41 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -362,12 +362,25 @@ _bt_check_unique(Relation rel, IndexTuple itup, Relation heapRel,
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a definite conflict.
|
||||
* This is a definite conflict. Break the tuple down
|
||||
* into datums and report the error. But first, make
|
||||
* sure we release the buffer locks we're holding ---
|
||||
* the error reporting code could make catalog accesses,
|
||||
* which in the worst case might touch this same index
|
||||
* and cause deadlocks.
|
||||
*/
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNIQUE_VIOLATION),
|
||||
errmsg("duplicate key value violates unique constraint \"%s\"",
|
||||
RelationGetRelationName(rel))));
|
||||
if (nbuf != InvalidBuffer)
|
||||
_bt_relbuf(rel, nbuf);
|
||||
_bt_relbuf(rel, buf);
|
||||
|
||||
{
|
||||
Datum values[INDEX_MAX_KEYS];
|
||||
bool isnull[INDEX_MAX_KEYS];
|
||||
|
||||
index_deform_tuple(itup, RelationGetDescr(rel),
|
||||
values, isnull);
|
||||
ReportUniqueViolation(rel, values, isnull);
|
||||
}
|
||||
}
|
||||
else if (all_dead)
|
||||
{
|
||||
|
Reference in New Issue
Block a user