summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorAlvaro Herrera2015-02-27 22:19:34 +0000
committerAlvaro Herrera2015-02-27 22:19:34 +0000
commitfbef4342a86522c98cd605891ad8c1145a61d191 (patch)
tree3889d6b7cebb234921700fdcae3bd8243fd756af /src/backend
parentf65e8270587f3e9b8224e20f7d020ed1f816dfe1 (diff)
Make CREATE OR REPLACE VIEW internally more consistent
The way that columns are added to a view is by calling AlterTableInternal with special subtype AT_AddColumnToView; but that subtype is changed to AT_AddColumnRecurse by ATPrepAddColumn. This has no visible effect in the current code, since views cannot have inheritance children (thus the recursion step is a no-op) and adding a column to a view is executed identically to doing it to a table; but it does make a difference for future event trigger code keeping track of commands, because the current situation leads to confusing the case with a normal ALTER TABLE ADD COLUMN. Fix the problem by passing a flag to ATPrepAddColumn to prevent it from changing the command subtype. The event trigger code can then properly ignore the subcommand. (We could remove the call to ATPrepAddColumn, since views are never typed, and there is never a need for recursion, which are the two conditions that are checked by ATPrepAddColumn; but it seems more future-proof to keep the call in place.)
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/commands/tablecmds.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index f5d5b6302f6..07ab4b434f5 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -325,7 +325,7 @@ static void ATTypedTableRecursion(List **wqueue, Relation rel, AlterTableCmd *cm
static List *find_typed_table_dependencies(Oid typeOid, const char *typeName,
DropBehavior behavior);
static void ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
- AlterTableCmd *cmd, LOCKMODE lockmode);
+ bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode);
static void ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
ColumnDef *colDef, bool isOid,
bool recurse, bool recursing, LOCKMODE lockmode);
@@ -3085,14 +3085,16 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
case AT_AddColumn: /* ADD COLUMN */
ATSimplePermissions(rel,
ATT_TABLE | ATT_COMPOSITE_TYPE | ATT_FOREIGN_TABLE);
- ATPrepAddColumn(wqueue, rel, recurse, recursing, cmd, lockmode);
+ ATPrepAddColumn(wqueue, rel, recurse, recursing, false, cmd,
+ lockmode);
/* Recursion occurs during execution phase */
pass = AT_PASS_ADD_COL;
break;
case AT_AddColumnToView: /* add column via CREATE OR REPLACE
* VIEW */
ATSimplePermissions(rel, ATT_VIEW);
- ATPrepAddColumn(wqueue, rel, recurse, recursing, cmd, lockmode);
+ ATPrepAddColumn(wqueue, rel, recurse, recursing, true, cmd,
+ lockmode);
/* Recursion occurs during execution phase */
pass = AT_PASS_ADD_COL;
break;
@@ -4576,7 +4578,7 @@ check_of_type(HeapTuple typetuple)
*/
static void
ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
- AlterTableCmd *cmd, LOCKMODE lockmode)
+ bool is_view, AlterTableCmd *cmd, LOCKMODE lockmode)
{
if (rel->rd_rel->reloftype && !recursing)
ereport(ERROR,
@@ -4586,7 +4588,7 @@ ATPrepAddColumn(List **wqueue, Relation rel, bool recurse, bool recursing,
if (rel->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
ATTypedTableRecursion(wqueue, rel, cmd, lockmode);
- if (recurse)
+ if (recurse && !is_view)
cmd->subtype = AT_AddColumnRecurse;
}
@@ -5026,7 +5028,7 @@ ATPrepAddOids(List **wqueue, Relation rel, bool recurse, AlterTableCmd *cmd, LOC
cdef->location = -1;
cmd->def = (Node *) cdef;
}
- ATPrepAddColumn(wqueue, rel, recurse, false, cmd, lockmode);
+ ATPrepAddColumn(wqueue, rel, recurse, false, false, cmd, lockmode);
if (recurse)
cmd->subtype = AT_AddOidsRecurse;