Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix ADD IF NOT EXISTS used in conjunction with ALTER TABLE ONLY
authorGreg Stark <stark@mit.edu>
Wed, 19 Dec 2018 23:28:35 +0000 (18:28 -0500)
committerGreg Stark <stark@mit.edu>
Thu, 20 Dec 2018 00:38:31 +0000 (19:38 -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 eef3b3a26cbd8e34f794faced59216b25cc818e7..ad8c17679333a0c041742b5158fc77431de899f4 100644 (file)
@@ -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,
index 889b15fb8e9cd08c3244a6fec57269df2c2b16bd..27cf550396659898705d966077d982af210591c4 100644 (file)
@@ -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 
index 9b87fbcf6d768fd40f1da7a25b9d6902da24b295..a498e4e99c80e1cfbbdfe254d32077e469e9e68e 100644 (file)
@@ -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