diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-07-30 02:45:38 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-07-30 02:45:38 +0000 |
commit | 060baf27844163c0874c72d7baf08d3bf9a8ffce (patch) | |
tree | b011e0000cb299f0c9ffb634931e30fcec3d2094 /src/backend/commands/typecmds.c | |
parent | 78aef14c5935bca92d0cacaa9d188f588d7f2444 (diff) | |
download | postgresql-060baf27844163c0874c72d7baf08d3bf9a8ffce.tar.gz postgresql-060baf27844163c0874c72d7baf08d3bf9a8ffce.zip |
Merge the Constraint and FkConstraint node types into a single type.
This was foreseen to be a good idea long ago, but nobody had got round
to doing it. The recent patch for deferred unique constraints made
transformConstraintAttrs() ugly enough that I decided it was time.
This change will also greatly simplify parsing of deferred CHECK constraints,
if anyone ever gets around to implementing that.
While at it, add a location field to Constraint, and use that to provide
an error cursor for some of the constraint-related error messages.
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r-- | src/backend/commands/typecmds.c | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 1d3077cc324..5fa2ac6bc90 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.136 2009/07/28 02:56:30 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.137 2009/07/30 02:45:36 tgl Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -867,22 +867,11 @@ DefineDomain(CreateDomainStmt *stmt) */ foreach(listptr, schema) { - Node *newConstraint = lfirst(listptr); - Constraint *constr; - - /* Check for unsupported constraint types */ - if (IsA(newConstraint, FkConstraint)) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("foreign key constraints not possible for domains"))); + Constraint *constr = lfirst(listptr); - /* otherwise it should be a plain Constraint */ - if (!IsA(newConstraint, Constraint)) + if (!IsA(constr, Constraint)) elog(ERROR, "unrecognized node type: %d", - (int) nodeTag(newConstraint)); - - constr = (Constraint *) newConstraint; - + (int) nodeTag(constr)); switch (constr->contype) { case CONSTR_DEFAULT: @@ -995,6 +984,12 @@ DefineDomain(CreateDomainStmt *stmt) errmsg("primary key constraints not possible for domains"))); break; + case CONSTR_FOREIGN: + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("foreign key constraints not possible for domains"))); + break; + case CONSTR_ATTR_DEFERRABLE: case CONSTR_ATTR_NOT_DEFERRABLE: case CONSTR_ATTR_DEFERRED: @@ -1849,13 +1844,6 @@ AlterDomainAddConstraint(List *names, Node *newConstraint) /* Check it's a domain and check user has permission for ALTER DOMAIN */ checkDomainOwner(tup, typename); - /* Check for unsupported constraint types */ - if (IsA(newConstraint, FkConstraint)) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("foreign key constraints not possible for domains"))); - - /* otherwise it should be a plain Constraint */ if (!IsA(newConstraint, Constraint)) elog(ERROR, "unrecognized node type: %d", (int) nodeTag(newConstraint)); @@ -1880,6 +1868,12 @@ AlterDomainAddConstraint(List *names, Node *newConstraint) errmsg("primary key constraints not possible for domains"))); break; + case CONSTR_FOREIGN: + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("foreign key constraints not possible for domains"))); + break; + case CONSTR_ATTR_DEFERRABLE: case CONSTR_ATTR_NOT_DEFERRABLE: case CONSTR_ATTR_DEFERRED: @@ -2188,23 +2182,23 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, /* * Assign or validate constraint name */ - if (constr->name) + if (constr->conname) { if (ConstraintNameIsUsed(CONSTRAINT_DOMAIN, domainOid, domainNamespace, - constr->name)) + constr->conname)) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("constraint \"%s\" for domain \"%s\" already exists", - constr->name, domainName))); + constr->conname, domainName))); } else - constr->name = ChooseConstraintName(domainName, - NULL, - "check", - domainNamespace, - NIL); + constr->conname = ChooseConstraintName(domainName, + NULL, + "check", + domainNamespace, + NIL); /* * Convert the A_EXPR in raw_expr into an EXPR @@ -2284,7 +2278,7 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, /* * Store the constraint in pg_constraint */ - CreateConstraintEntry(constr->name, /* Constraint Name */ + CreateConstraintEntry(constr->conname, /* Constraint Name */ domainNamespace, /* namespace */ CONSTRAINT_CHECK, /* Constraint Type */ false, /* Is Deferrable */ |