diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-06-20 18:21:15 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-06-20 18:21:15 +0000 |
commit | 12b9a64ccced721780f7e27102a48ae582e7530c (patch) | |
tree | d581741f79a7e80eee7ee5fb07a7d06d468a2b26 | |
parent | f5bfaf9546de18aaeea6ebd4fa08b4b9e98312c7 (diff) | |
download | postgresql-12b9a64ccced721780f7e27102a48ae582e7530c.tar.gz postgresql-12b9a64ccced721780f7e27102a48ae582e7530c.zip |
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.
-rw-r--r-- | src/backend/parser/analyze.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index f88f173b59b..78d96697415 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.326.2.3 2006/10/11 20:03:11 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.326.2.4 2007/06/20 18:21:15 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -820,6 +820,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, { bool is_serial; bool saw_nullable; + bool saw_default; Constraint *constraint; ListCell *clist; @@ -938,6 +939,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, transformConstraintAttrs(column->constraints); saw_nullable = false; + saw_default = false; foreach(clist, column->constraints) { @@ -982,13 +984,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: |