aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/typecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-01-29 17:06:26 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-01-29 17:08:26 -0500
commit991f3e5ab3f8196d18d5b313c81a5f744f3baaea (patch)
tree376f7a4bc5541156a3c270304dc22333f2ba6955 /src/backend/commands/typecmds.c
parent89d00cbe01447fd36edbc3bed659f869b18172d1 (diff)
downloadpostgresql-991f3e5ab3f8196d18d5b313c81a5f744f3baaea.tar.gz
postgresql-991f3e5ab3f8196d18d5b313c81a5f744f3baaea.zip
Provide database object names as separate fields in error messages.
This patch addresses the problem that applications currently have to extract object names from possibly-localized textual error messages, if they want to know for example which index caused a UNIQUE_VIOLATION failure. It adds new error message fields to the wire protocol, which can carry the name of a table, table column, data type, or constraint associated with the error. (Since the protocol spec has always instructed clients to ignore unrecognized field types, this should not create any compatibility problem.) Support for providing these new fields has been added to just a limited set of error reports (mainly, those in the "integrity constraint violation" SQLSTATE class), but we will doubtless add them to more calls in future. Pavel Stehule, reviewed and extensively revised by Peter Geoghegan, with additional hacking by Tom Lane.
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r--src/backend/commands/typecmds.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 7a724161f11..0e55263d4ef 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -2264,11 +2264,22 @@ AlterDomainNotNull(List *names, bool notNull)
int attnum = rtc->atts[i];
if (heap_attisnull(tuple, attnum))
+ {
+ /*
+ * In principle the auxiliary information for this
+ * error should be errdatatype(), but errtablecol()
+ * seems considerably more useful in practice. Since
+ * this code only executes in an ALTER DOMAIN command,
+ * the client should already know which domain is in
+ * question.
+ */
ereport(ERROR,
(errcode(ERRCODE_NOT_NULL_VIOLATION),
errmsg("column \"%s\" of table \"%s\" contains null values",
NameStr(tupdesc->attrs[attnum - 1]->attname),
- RelationGetRelationName(testrel))));
+ RelationGetRelationName(testrel)),
+ errtablecol(testrel, attnum)));
+ }
}
}
heap_endscan(scan);
@@ -2469,7 +2480,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
* to pg_constraint.
*/
- ccbin = domainAddConstraint(HeapTupleGetOid(tup), typTup->typnamespace,
+ ccbin = domainAddConstraint(domainoid, typTup->typnamespace,
typTup->typbasetype, typTup->typtypmod,
constr, NameStr(typTup->typname));
@@ -2641,11 +2652,22 @@ validateDomainConstraint(Oid domainoid, char *ccbin)
&isNull, NULL);
if (!isNull && !DatumGetBool(conResult))
+ {
+ /*
+ * In principle the auxiliary information for this error
+ * should be errdomainconstraint(), but errtablecol()
+ * seems considerably more useful in practice. Since this
+ * code only executes in an ALTER DOMAIN command, the
+ * client should already know which domain is in question,
+ * and which constraint too.
+ */
ereport(ERROR,
(errcode(ERRCODE_CHECK_VIOLATION),
errmsg("column \"%s\" of table \"%s\" contains values that violate the new constraint",
NameStr(tupdesc->attrs[attnum - 1]->attname),
- RelationGetRelationName(testrel))));
+ RelationGetRelationName(testrel)),
+ errtablecol(testrel, attnum)));
+ }
}
ResetExprContext(econtext);