88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.75 2009/08/01 19 :59:41 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/access/index/genam.c,v 1.76 2009/08/01 20 :59:17 tgl Exp $
1212 *
1313 * NOTES
1414 * many of the old access method routines have been turned into
@@ -133,13 +133,16 @@ IndexScanEnd(IndexScanDesc scan)
133133}
134134
135135/*
136- * ReportUniqueViolation -- Report a unique-constraint violation.
136+ * BuildIndexValueDescription
137137 *
138- * The index entry represented by values[]/isnull[] violates the unique
139- * constraint enforced by this index. Throw a suitable error.
138+ * Construct a string describing the contents of an index entry, in the
139+ * form "(key_name, ...)=(key_value, ...)". This is currently used
140+ * only for building unique-constraint error messages, but we don't want
141+ * to hardwire the spelling of the messages here.
140142 */
141- void
142- ReportUniqueViolation (Relation indexRelation , Datum * values , bool * isnull )
143+ char *
144+ BuildIndexValueDescription (Relation indexRelation ,
145+ Datum * values , bool * isnull )
143146{
144147 /*
145148 * XXX for the moment we use the index's tupdesc as a guide to the
@@ -148,14 +151,14 @@ ReportUniqueViolation(Relation indexRelation, Datum *values, bool *isnull)
148151 * are ever to support non-btree unique indexes.
149152 */
150153 TupleDesc tupdesc = RelationGetDescr (indexRelation );
151- char * key_names ;
152- StringInfoData key_values ;
154+ StringInfoData buf ;
153155 int i ;
154156
155- key_names = pg_get_indexdef_columns (RelationGetRelid (indexRelation ), true);
157+ initStringInfo (& buf );
158+ appendStringInfo (& buf , "(%s)=(" ,
159+ pg_get_indexdef_columns (RelationGetRelid (indexRelation ),
160+ true));
156161
157- /* Get printable versions of the key values */
158- initStringInfo (& key_values );
159162 for (i = 0 ; i < tupdesc -> natts ; i ++ )
160163 {
161164 char * val ;
@@ -173,16 +176,13 @@ ReportUniqueViolation(Relation indexRelation, Datum *values, bool *isnull)
173176 }
174177
175178 if (i > 0 )
176- appendStringInfoString (& key_values , ", " );
177- appendStringInfoString (& key_values , val );
179+ appendStringInfoString (& buf , ", " );
180+ appendStringInfoString (& buf , val );
178181 }
179182
180- ereport (ERROR ,
181- (errcode (ERRCODE_UNIQUE_VIOLATION ),
182- errmsg ("duplicate key value violates unique constraint \"%s\"" ,
183- RelationGetRelationName (indexRelation )),
184- errdetail ("Key (%s)=(%s) already exists." ,
185- key_names , key_values .data )));
183+ appendStringInfoChar (& buf , ')' );
184+
185+ return buf .data ;
186186}
187187
188188
0 commit comments