From 56915ea29622e85b296b65e2fd6fd164c5bfd5d6 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 24 Jan 2005 23:22:13 +0000 Subject: Fix ALTER TABLE ADD COLUMN so that constraints of domain types are enforced properly when there is no explicit default value for the new column. Per report from Craig Perras. --- src/backend/commands/typecmds.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/backend/commands/typecmds.c') diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index efeb3f3bab2..ef45d119868 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.65 2004/12/31 21:59:42 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.65.4.1 2005/01/24 23:22:13 tgl Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -1929,6 +1929,9 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, * This is called by the executor during plan startup for a CoerceToDomain * expression node. The given constraints will be checked for each value * passed through the node. + * + * We allow this to be called for non-domain types, in which case the result + * is always NIL. */ List * GetDomainConstraints(Oid typeOid) @@ -1954,6 +1957,13 @@ GetDomainConstraints(Oid typeOid) elog(ERROR, "cache lookup failed for type %u", typeOid); typTup = (Form_pg_type) GETSTRUCT(tup); + if (typTup->typtype != 'd') + { + /* Not a domain, so done */ + ReleaseSysCache(tup); + break; + } + /* Test for NOT NULL Constraint */ if (typTup->typnotnull) notNull = true; @@ -2010,14 +2020,7 @@ GetDomainConstraints(Oid typeOid) systable_endscan(scan); - if (typTup->typtype != 'd') - { - /* Not a domain, so done */ - ReleaseSysCache(tup); - break; - } - - /* else loop to next domain in stack */ + /* loop to next domain in stack */ typeOid = typTup->typbasetype; ReleaseSysCache(tup); } -- cgit v1.2.3