deparse: Support for ALTER TABLE ONLY
authorPetr Jelinek <pjmodos@pjmodos.net>
Tue, 25 Nov 2014 14:38:38 +0000 (15:38 +0100)
committerPetr Jelinek <pjmodos@pjmodos.net>
Tue, 25 Nov 2014 14:38:38 +0000 (15:38 +0100)
src/backend/tcop/deparse_utility.c

index df333209f8cc39a4507780bb1499ad9abdbdcaab..33590116709c75a17220c600403dad6497ae19f1 100644 (file)
@@ -67,6 +67,7 @@
 #include "nodes/makefuncs.h"
 #include "nodes/parsenodes.h"
 #include "parser/analyze.h"
+#include "parser/parse_clause.h"
 #include "parser/parse_collate.h"
 #include "parser/parse_expr.h"
 #include "parser/parse_relation.h"
@@ -4320,13 +4321,17 @@ deparse_AlterTableStmt(StashedCommand *cmd)
    List       *subcmds = NIL;
    ListCell   *cell;
    char       *command;
+   AlterTableStmt *node = (AlterTableStmt *) cmd->parsetree;
 
    rel = heap_open(cmd->d.alterTable.objectId, AccessShareLock);
    dpcontext = deparse_context_for(RelationGetRelationName(rel),
                                    cmd->d.alterTable.objectId);
 
    alterTableStmt =
-       new_objtree_VA("ALTER TABLE %{identity}D %{subcmds:, }s", 0);
+       new_objtree_VA("ALTER TABLE %{only}s %{identity}D %{subcmds:, }s", 0);
+   append_string_object(alterTableStmt, "only",
+                        interpretInhOption(node->relation->inhOpt) ?
+                        "" : "ONLY");
    tmp = new_objtree_for_qualname(rel->rd_rel->relnamespace,
                                   RelationGetRelationName(rel));
    append_object_object(alterTableStmt, "identity", tmp);
@@ -4354,8 +4359,10 @@ deparse_AlterTableStmt(StashedCommand *cmd)
                                  new_object_object(NULL, tmp));
                break;
 
+           case AT_DropColumn:
            case AT_DropColumnRecurse:
            case AT_ValidateConstraintRecurse:
+           case AT_DropConstraint:
            case AT_DropConstraintRecurse:
            case AT_AddOidsRecurse:
            case AT_AddIndexConstraint:
@@ -4441,13 +4448,6 @@ deparse_AlterTableStmt(StashedCommand *cmd)
                subcmds = lappend(subcmds, new_object_object(NULL, tmp));
                break;
 
-           case AT_DropColumn:
-               tmp = new_objtree_VA("DROP COLUMN %{column}I",
-                                    2, "type", ObjTypeString, "drop column",
-                                "column", ObjTypeString, subcmd->name);
-               subcmds = lappend(subcmds, new_object_object(NULL, tmp));
-               break;
-
            case AT_AddIndex:
                {
                    Oid         idxOid = substashed->oid;
@@ -4504,13 +4504,6 @@ deparse_AlterTableStmt(StashedCommand *cmd)
                subcmds = lappend(subcmds, new_object_object(NULL, tmp));
                break;
 
-           case AT_DropConstraint:
-               tmp = new_objtree_VA("DROP CONSTRAINT %{constraint}I", 2,
-                                    "type", ObjTypeString, "drop constraint",
-                                    "constraint", ObjTypeString, subcmd->name);
-               subcmds = lappend(subcmds, new_object_object(NULL, tmp));
-               break;
-
            case AT_AlterColumnType:
                tmp = new_objtree_VA("ALTER COLUMN %{column}I SET DATA TYPE %{datatype}T collate_clause using_clause",
                                     2, "type", ObjTypeString, "alter column type",