From ef61ff0412686672808ad9d98a5c3a0278acbd53 Mon Sep 17 00:00:00 2001 From: Fizaa Luthra Date: Fri, 12 Apr 2019 13:24:37 -0700 Subject: [PATCH] [YSQL] ENG-4954 (#1124): Enabled DROP CONSTRAINT IF EXISTS Summary: Enabled DROP CONSTRAINT IF EXISTS in the parser and added a test in yb_feature_alter_table Test Plan: Added test for DROP CONSTRAINT IF EXISTS in yb_feature_alter_table Reviewers: neha Reviewed By: neha Subscribers: yql Differential Revision: https://phabricator.dev.yugabyte.com/D6474 --- src/postgres/src/backend/parser/gram.y | 1 - .../src/test/regress/expected/yb_feature_alter_table.out | 6 ++++++ .../src/test/regress/sql/yb_feature_alter_table.sql | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/postgres/src/backend/parser/gram.y b/src/postgres/src/backend/parser/gram.y index 6dadbac8e048..9c7814f96ea4 100644 --- a/src/postgres/src/backend/parser/gram.y +++ b/src/postgres/src/backend/parser/gram.y @@ -2401,7 +2401,6 @@ alter_table_cmd: /* ALTER TABLE DROP CONSTRAINT IF EXISTS [RESTRICT|CASCADE] */ | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior { - parser_ybc_signal_unsupported(@1, "ALTER TABLE DROP CONSTRAINT", 1124); AlterTableCmd *n = makeNode(AlterTableCmd); n->subtype = AT_DropConstraint; n->name = $5; diff --git a/src/postgres/src/test/regress/expected/yb_feature_alter_table.out b/src/postgres/src/test/regress/expected/yb_feature_alter_table.out index 655371ba758b..b02e21d35921 100644 --- a/src/postgres/src/test/regress/expected/yb_feature_alter_table.out +++ b/src/postgres/src/test/regress/expected/yb_feature_alter_table.out @@ -228,12 +228,18 @@ alter table atacc1 add constraint checkb check (b < 0); -- should fail ERROR: check constraint "checkb" is violated by some row alter table atacc1 add constraint checkb check (b > 0); alter table atacc1 add constraint checkb2 check (b > 10); +alter table atacc1 add constraint checkb3 check (b > 10); insert into atacc1 values (5, 5, 5); -- should fail ERROR: new row for relation "atacc1" violates check constraint "checkb2" DETAIL: Failing row contains (5, 5, 5). alter table atacc1 drop constraint checkb2; insert into atacc1 values (5, 5, 5); +ERROR: new row for relation "atacc1" violates check constraint "checkb3" +DETAIL: Failing row contains (5, 5, 5). alter table atacc1 drop constraint checkb; +alter table atacc1 drop constraint if exists checkb2; +NOTICE: constraint "checkb2" of relation "atacc1" does not exist, skipping +alter table atacc1 drop constraint if exists checkb3; delete from atacc1 where b = 5; -- test rename alter table atacc1 rename b to e; diff --git a/src/postgres/src/test/regress/sql/yb_feature_alter_table.sql b/src/postgres/src/test/regress/sql/yb_feature_alter_table.sql index 42b9b7581482..0f855e58c05c 100644 --- a/src/postgres/src/test/regress/sql/yb_feature_alter_table.sql +++ b/src/postgres/src/test/regress/sql/yb_feature_alter_table.sql @@ -128,10 +128,13 @@ drop table test2; alter table atacc1 add constraint checkb check (b < 0); -- should fail alter table atacc1 add constraint checkb check (b > 0); alter table atacc1 add constraint checkb2 check (b > 10); +alter table atacc1 add constraint checkb3 check (b > 10); insert into atacc1 values (5, 5, 5); -- should fail alter table atacc1 drop constraint checkb2; insert into atacc1 values (5, 5, 5); alter table atacc1 drop constraint checkb; +alter table atacc1 drop constraint if exists checkb2; +alter table atacc1 drop constraint if exists checkb3; delete from atacc1 where b = 5; -- test rename