Commit 1075dfda authored by Greg Stark's avatar Greg Stark

Fix ADD IF NOT EXISTS used in conjunction with ALTER TABLE ONLY

The flag for IF NOT EXISTS was only being passed down in the normal
recursing case. It's been this way since originally added in 9.6 in
commit 2cd40adb so backpatch back to 9.6.
parent 2ece7c07
......@@ -4054,7 +4054,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
case AT_AddColumnToView: /* add column via CREATE OR REPLACE VIEW */
address = ATExecAddColumn(wqueue, tab, rel, (ColumnDef *) cmd->def,
false, false,
false, lockmode);
cmd->missing_ok, lockmode);
break;
case AT_AddColumnRecurse:
address = ATExecAddColumn(wqueue, tab, rel, (ColumnDef *) cmd->def,
......
......@@ -3173,6 +3173,9 @@ ALTER TABLE test_add_column
ALTER TABLE test_add_column
ADD COLUMN c2 integer; -- fail because c2 already exists
ERROR: column "c2" of relation "test_add_column" already exists
ALTER TABLE ONLY test_add_column
ADD COLUMN c2 integer; -- fail because c2 already exists
ERROR: column "c2" of relation "test_add_column" already exists
\d test_add_column
Table "public.test_add_column"
Column | Type | Collation | Nullable | Default
......@@ -3183,6 +3186,9 @@ ERROR: column "c2" of relation "test_add_column" already exists
ALTER TABLE test_add_column
ADD COLUMN IF NOT EXISTS c2 integer; -- skipping because c2 already exists
NOTICE: column "c2" of relation "test_add_column" already exists, skipping
ALTER TABLE ONLY test_add_column
ADD COLUMN IF NOT EXISTS c2 integer; -- skipping because c2 already exists
NOTICE: column "c2" of relation "test_add_column" already exists, skipping
\d test_add_column
Table "public.test_add_column"
Column | Type | Collation | Nullable | Default
......
......@@ -1971,9 +1971,13 @@ ALTER TABLE test_add_column
\d test_add_column
ALTER TABLE test_add_column
ADD COLUMN c2 integer; -- fail because c2 already exists
ALTER TABLE ONLY test_add_column
ADD COLUMN c2 integer; -- fail because c2 already exists
\d test_add_column
ALTER TABLE test_add_column
ADD COLUMN IF NOT EXISTS c2 integer; -- skipping because c2 already exists
ALTER TABLE ONLY test_add_column
ADD COLUMN IF NOT EXISTS c2 integer; -- skipping because c2 already exists
\d test_add_column
ALTER TABLE test_add_column
ADD COLUMN c2 integer, -- fail because c2 already exists
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment