Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cd40735

Browse files
committed
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.
1 parent a060d5f commit cd40735

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/backend/parser/analyze.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
2121
* Portions Copyright (c) 1994, Regents of the University of California
2222
*
23-
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.365 2007/06/19 21:24:48 neilc Exp $
23+
* $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.366 2007/06/20 18:21:00 tgl Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -956,6 +956,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
956956
{
957957
bool is_serial;
958958
bool saw_nullable;
959+
bool saw_default;
959960
Constraint *constraint;
960961
ListCell *clist;
961962

@@ -1086,6 +1087,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
10861087
transformConstraintAttrs(column->constraints);
10871088

10881089
saw_nullable = false;
1090+
saw_default = false;
10891091

10901092
foreach(clist, column->constraints)
10911093
{
@@ -1130,13 +1132,15 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
11301132
break;
11311133

11321134
case CONSTR_DEFAULT:
1133-
if (column->raw_default != NULL)
1135+
if (saw_default)
11341136
ereport(ERROR,
11351137
(errcode(ERRCODE_SYNTAX_ERROR),
11361138
errmsg("multiple default values specified for column \"%s\" of table \"%s\"",
11371139
column->colname, cxt->relation->relname)));
1140+
/* Note: DEFAULT NULL maps to constraint->raw_expr == NULL */
11381141
column->raw_default = constraint->raw_expr;
11391142
Assert(constraint->cooked_expr == NULL);
1143+
saw_default = true;
11401144
break;
11411145

11421146
case CONSTR_PRIMARY:

0 commit comments

Comments
 (0)