transformColumnDefinition failed to complain about
authorTom Lane <[email protected]>
Wed, 20 Jun 2007 18:21:51 +0000 (18:21 +0000)
committerTom Lane <[email protected]>
Wed, 20 Jun 2007 18:21:51 +0000 (18:21 +0000)
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.

src/backend/parser/analyze.c

index d19984c8e5235178e3cca2d67cf969b13af5594f..fc4f81a7cca9a4975637864329b1b2069bbc4e7c 100644 (file)
@@ -793,6 +793,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
 {
        bool            is_serial;
        bool            saw_nullable;
+       bool            saw_default;
        Constraint *constraint;
        List       *clist;
 
@@ -895,6 +896,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
        transformConstraintAttrs(column->constraints);
 
        saw_nullable = false;
+       saw_default = false;
 
        foreach(clist, column->constraints)
        {
@@ -935,11 +937,13 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
                                break;
 
                        case CONSTR_DEFAULT:
-                               if (column->raw_default != NULL)
+                               if (saw_default)
                                        elog(ERROR, "%s/DEFAULT multiple values specified for '%s.%s'",
                                                 cxt->stmtType, cxt->relation->relname, column->colname);
+                               /* 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: