Skip to content

Commit 46e9709

Browse files
committed
Remove transformAlterTableStmt's kluge to replace ColumnDef.is_not_null
flags by separate AT_SetNotNull subcommands. That was always ugly and inefficient, and it's now clear that it was merely a partial workaround for the bug just identified in ATExecAddColumn. This is just code beautification not a bug fix, so no back-patch. Brendan Jurd, with some trivial additional cleanup by me.
1 parent bb908d9 commit 46e9709

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

src/backend/parser/parse_utilcmd.c

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
22-
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.11 2008/03/25 22:42:43 tgl Exp $
22+
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.12 2008/04/24 20:46:49 tgl Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -1718,49 +1718,30 @@ transformAlterTableStmt(AlterTableStmt *stmt, const char *queryString)
17181718
{
17191719
ColumnDef *def = (ColumnDef *) cmd->def;
17201720

1721-
Assert(IsA(cmd->def, ColumnDef));
1722-
transformColumnDefinition(pstate, &cxt,
1723-
(ColumnDef *) cmd->def);
1721+
Assert(IsA(def, ColumnDef));
1722+
transformColumnDefinition(pstate, &cxt, def);
17241723

17251724
/*
17261725
* If the column has a non-null default, we can't skip
17271726
* validation of foreign keys.
17281727
*/
1729-
if (((ColumnDef *) cmd->def)->raw_default != NULL)
1728+
if (def->raw_default != NULL)
17301729
skipValidation = false;
17311730

1732-
newcmds = lappend(newcmds, cmd);
1733-
1734-
/*
1735-
* Convert an ADD COLUMN ... NOT NULL constraint to a
1736-
* separate command
1737-
*/
1738-
if (def->is_not_null)
1739-
{
1740-
/* Remove NOT NULL from AddColumn */
1741-
def->is_not_null = false;
1742-
1743-
/* Add as a separate AlterTableCmd */
1744-
newcmd = makeNode(AlterTableCmd);
1745-
newcmd->subtype = AT_SetNotNull;
1746-
newcmd->name = pstrdup(def->colname);
1747-
newcmds = lappend(newcmds, newcmd);
1748-
}
1749-
17501731
/*
17511732
* All constraints are processed in other ways. Remove the
17521733
* original list
17531734
*/
17541735
def->constraints = NIL;
17551736

1737+
newcmds = lappend(newcmds, cmd);
17561738
break;
17571739
}
17581740
case AT_AddConstraint:
17591741

17601742
/*
17611743
* The original AddConstraint cmd node doesn't go to newcmds
17621744
*/
1763-
17641745
if (IsA(cmd->def, Constraint))
17651746
transformTableConstraint(pstate, &cxt,
17661747
(Constraint *) cmd->def);

0 commit comments

Comments
 (0)