aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/typecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-01-24 23:21:57 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-01-24 23:21:57 +0000
commitbeaf5ae623f9dd323da095fb65c74768ebc8afc5 (patch)
tree043a8b654c2388bda4ac1b6220c5666cb80a2549 /src/backend/commands/typecmds.c
parentad538d8bcd882f04ac1faa35ba2924ddbe9ffed3 (diff)
downloadpostgresql-beaf5ae623f9dd323da095fb65c74768ebc8afc5.tar.gz
postgresql-beaf5ae623f9dd323da095fb65c74768ebc8afc5.zip
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.
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r--src/backend/commands/typecmds.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index efeb3f3bab2..d9fffbec271 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.66 2005/01/24 23:21:57 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);
}