Fix ADD IF NOT EXISTS used in conjunction with ALTER TABLE ONLY
authorGreg Stark
Wed, 19 Dec 2018 23:28:35 +0000 (18:28 -0500)
committerGreg Stark
Thu, 20 Dec 2018 00:41:06 +0000 (19:41 -0500)
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 2cd40adb85 so backpatch back to 9.6.

src/backend/commands/tablecmds.c
src/test/regress/expected/alter_table.out
src/test/regress/sql/alter_table.sql

index 04795a33a4346454ed57274cc1da632848c3cb08..08e9bfcbf1857a94158c34dfd1bec1b806bd167c 100644 (file)
@@ -3832,7 +3832,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,
-                                     false, lockmode);
+                                     cmd->missing_ok, lockmode);
            break;
        case AT_AddColumnRecurse:
            address = ATExecAddColumn(wqueue, tab, rel, (ColumnDef *) cmd->def,
index 20f7d926b29e94d360cd296afa1d225010d540f6..f469bfed65da08893ecf6fe2f56bc5ac8a924c03 100644 (file)
@@ -3153,6 +3153,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 
@@ -3163,6 +3166,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 
index ea94eb8f162a966430642449145521e7387b55f8..447cd6fa0142dafce6b6e09d16af3268590e9dcf 100644 (file)
@@ -1970,9 +1970,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