Remove transformAlterTableStmt's kluge to replace ColumnDef.is_not_null
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 Apr 2008 20:46:49 +0000 (20:46 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 Apr 2008 20:46:49 +0000 (20:46 +0000)
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.

src/backend/parser/parse_utilcmd.c

index f2087e47d7f10dba7bb1d64f2475b24fb2341d51..66cc0b5e90fe411f56015062843e0b27788311e3 100644 (file)
@@ -1718,41 +1718,23 @@ transformAlterTableStmt(AlterTableStmt *stmt, const char *queryString)
                                {
                                        ColumnDef  *def = (ColumnDef *) cmd->def;
 
-                                       Assert(IsA(cmd->def, ColumnDef));
-                                       transformColumnDefinition(pstate, &cxt,
-                                                                                         (ColumnDef *) cmd->def);
+                                       Assert(IsA(def, ColumnDef));
+                                       transformColumnDefinition(pstate, &cxt, def);
 
                                        /*
                                         * If the column has a non-null default, we can't skip
                                         * validation of foreign keys.
                                         */
-                                       if (((ColumnDef *) cmd->def)->raw_default != NULL)
+                                       if (def->raw_default != NULL)
                                                skipValidation = false;
 
-                                       newcmds = lappend(newcmds, cmd);
-
-                                       /*
-                                        * Convert an ADD COLUMN ... NOT NULL constraint to a
-                                        * separate command
-                                        */
-                                       if (def->is_not_null)
-                                       {
-                                               /* Remove NOT NULL from AddColumn */
-                                               def->is_not_null = false;
-
-                                               /* Add as a separate AlterTableCmd */
-                                               newcmd = makeNode(AlterTableCmd);
-                                               newcmd->subtype = AT_SetNotNull;
-                                               newcmd->name = pstrdup(def->colname);
-                                               newcmds = lappend(newcmds, newcmd);
-                                       }
-
                                        /*
                                         * All constraints are processed in other ways. Remove the
                                         * original list
                                         */
                                        def->constraints = NIL;
 
+                                       newcmds = lappend(newcmds, cmd);
                                        break;
                                }
                        case AT_AddConstraint:
@@ -1760,7 +1742,6 @@ transformAlterTableStmt(AlterTableStmt *stmt, const char *queryString)
                                /*
                                 * The original AddConstraint cmd node doesn't go to newcmds
                                 */
-
                                if (IsA(cmd->def, Constraint))
                                        transformTableConstraint(pstate, &cxt,
                                                                                         (Constraint *) cmd->def);