From: Tom Lane Date: Wed, 20 Jun 2007 18:21:51 +0000 (+0000) Subject: transformColumnDefinition failed to complain about X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=b9a7a681e7520709e66cd71b545ddf7c708026fa;p=users%2Fbernd%2Fpostgres.git transformColumnDefinition failed to complain about create table foo (bar int default null default 3); due to not thinking about the special-case handling of DEFAULT NULL. Problem noticed while investigating bug #3396. --- diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 2ad624c108..a7bf9ab7f8 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -956,6 +956,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, { bool is_serial; bool saw_nullable; + bool saw_default; Constraint *constraint; ListCell *clist; @@ -1086,6 +1087,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, transformConstraintAttrs(column->constraints); saw_nullable = false; + saw_default = false; foreach(clist, column->constraints) { @@ -1130,13 +1132,15 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, break; case CONSTR_DEFAULT: - if (column->raw_default != NULL) + if (saw_default) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("multiple default values specified for column \"%s\" of table \"%s\"", column->colname, cxt->relation->relname))); + /* Note: DEFAULT NULL maps to constraint->raw_expr == NULL */ column->raw_default = constraint->raw_expr; Assert(constraint->cooked_expr == NULL); + saw_default = true; break; case CONSTR_PRIMARY: