Skip to content

Commit

Permalink
[YSQL] ENG-4954 (#1124): Enabled DROP CONSTRAINT IF EXISTS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fizaaluthra committed Apr 15, 2019
1 parent 8e109ea commit ef61ff0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/postgres/src/backend/parser/gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,6 @@ alter_table_cmd:
/* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/postgres/src/test/regress/sql/yb_feature_alter_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ef61ff0

Please sign in to comment.