From 5668afeb6d25ef842ff14239c5ba3aa20cf56937 Mon Sep 17 00:00:00 2001 From: Greg Stark Date: Wed, 19 Dec 2018 18:28:35 -0500 Subject: [PATCH] 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 2cd40adb85 so backpatch back to 9.6. --- src/backend/commands/tablecmds.c | 2 +- src/test/regress/expected/alter_table.out | 6 ++++++ src/test/regress/sql/alter_table.sql | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 7a30da5d0d..78e3001771 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -3477,7 +3477,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, * 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, diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index b5c4e82410..78bc4ffde6 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -3153,6 +3153,9 @@ Table "public.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 | Modifiers @@ -3163,6 +3166,9 @@ Table "public.test_add_column" 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 | Modifiers diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql index fdc300d6b7..f9f952eb87 100644 --- a/src/test/regress/sql/alter_table.sql +++ b/src/test/regress/sql/alter_table.sql @@ -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 -- 2.40.0