1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-17 06:41:24 +03:00

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.
This commit is contained in:
Tom Lane 2007-06-20 18:21:39 +00:00
parent 4ed20db4f4
commit d9544b67ce

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.290.2.4 2006/10/11 20:03:26 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.290.2.5 2007/06/20 18:21:39 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -962,6 +962,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
{ {
bool is_serial; bool is_serial;
bool saw_nullable; bool saw_nullable;
bool saw_default;
Constraint *constraint; Constraint *constraint;
List *clist; List *clist;
@ -1066,6 +1067,7 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
transformConstraintAttrs(column->constraints); transformConstraintAttrs(column->constraints);
saw_nullable = false; saw_nullable = false;
saw_default = false;
foreach(clist, column->constraints) foreach(clist, column->constraints)
{ {
@ -1110,13 +1112,15 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
break; break;
case CONSTR_DEFAULT: case CONSTR_DEFAULT:
if (column->raw_default != NULL) if (saw_default)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("multiple default values specified for column \"%s\" of table \"%s\"", errmsg("multiple default values specified for column \"%s\" of table \"%s\"",
column->colname, cxt->relation->relname))); column->colname, cxt->relation->relname)));
/* Note: DEFAULT NULL maps to constraint->raw_expr == NULL */
column->raw_default = constraint->raw_expr; column->raw_default = constraint->raw_expr;
Assert(constraint->cooked_expr == NULL); Assert(constraint->cooked_expr == NULL);
saw_default = true;
break; break;
case CONSTR_PRIMARY: case CONSTR_PRIMARY: