Add test for inherited CHECK constraint drop

This code is insufficiently covered by tests, so add a few small test
cases to immortalize its behavior before it gets rewritten completely by
the project to catalog NOT NULL constraints.
This commit is contained in:
Alvaro Herrera 2023-08-24 16:51:43 +02:00
parent b0bea38705
commit 3da13a6257
No known key found for this signature in database
GPG Key ID: 1C20ACB9D5C564AE
2 changed files with 148 additions and 0 deletions

View File

@ -1283,6 +1283,115 @@ order by 1, 2;
drop table p1 cascade;
NOTICE: drop cascades to table p1_c1
--
-- Test DROP behavior of multiply-defined CHECK constraints
--
create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
create table p1_c1 (f1 int constraint f1_pos CHECK (f1 > 0)) inherits (p1);
NOTICE: merging column "f1" with inherited definition
NOTICE: merging constraint "f1_pos" with inherited definition
alter table p1_c1 drop constraint f1_pos;
ERROR: cannot drop inherited constraint "f1_pos" of relation "p1_c1"
alter table p1 drop constraint f1_pos;
\d p1_c1
Table "public.p1_c1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
f1 | integer | | |
Check constraints:
"f1_pos" CHECK (f1 > 0)
Inherits: p1
drop table p1 cascade;
NOTICE: drop cascades to table p1_c1
create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
create table p2(f1 int constraint f1_pos CHECK (f1 > 0));
create table p1p2_c1 (f1 int) inherits (p1, p2);
NOTICE: merging multiple inherited definitions of column "f1"
NOTICE: merging column "f1" with inherited definition
create table p1p2_c2 (f1 int constraint f1_pos CHECK (f1 > 0)) inherits (p1, p2);
NOTICE: merging multiple inherited definitions of column "f1"
NOTICE: merging column "f1" with inherited definition
NOTICE: merging constraint "f1_pos" with inherited definition
alter table p2 drop constraint f1_pos;
alter table p1 drop constraint f1_pos;
\d p1p2_c*
Table "public.p1p2_c1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
f1 | integer | | |
Inherits: p1,
p2
Table "public.p1p2_c2"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
f1 | integer | | |
Check constraints:
"f1_pos" CHECK (f1 > 0)
Inherits: p1,
p2
drop table p1, p2 cascade;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table p1p2_c1
drop cascades to table p1p2_c2
create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
create table p1_c1() inherits (p1);
create table p1_c2() inherits (p1);
create table p1_c1c2() inherits (p1_c1, p1_c2);
NOTICE: merging multiple inherited definitions of column "f1"
\d p1_c1c2
Table "public.p1_c1c2"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
f1 | integer | | |
Check constraints:
"f1_pos" CHECK (f1 > 0)
Inherits: p1_c1,
p1_c2
alter table p1 drop constraint f1_pos;
\d p1_c1c2
Table "public.p1_c1c2"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
f1 | integer | | |
Inherits: p1_c1,
p1_c2
drop table p1 cascade;
NOTICE: drop cascades to 3 other objects
DETAIL: drop cascades to table p1_c1
drop cascades to table p1_c2
drop cascades to table p1_c1c2
create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
create table p1_c1() inherits (p1);
create table p1_c2(constraint f1_pos CHECK (f1 > 0)) inherits (p1);
NOTICE: merging constraint "f1_pos" with inherited definition
create table p1_c1c2() inherits (p1_c1, p1_c2, p1);
NOTICE: merging multiple inherited definitions of column "f1"
NOTICE: merging multiple inherited definitions of column "f1"
alter table p1_c2 drop constraint f1_pos;
ERROR: cannot drop inherited constraint "f1_pos" of relation "p1_c2"
alter table p1 drop constraint f1_pos;
alter table p1_c1c2 drop constraint f1_pos;
ERROR: cannot drop inherited constraint "f1_pos" of relation "p1_c1c2"
alter table p1_c2 drop constraint f1_pos;
\d p1_c1c2
Table "public.p1_c1c2"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
f1 | integer | | |
Inherits: p1_c1,
p1_c2,
p1
drop table p1 cascade;
NOTICE: drop cascades to 3 other objects
DETAIL: drop cascades to table p1_c1
drop cascades to table p1_c2
drop cascades to table p1_c1c2
-- Test that a valid child can have not-valid parent, but not vice versa
create table invalid_check_con(f1 int);
create table invalid_check_con_child() inherits(invalid_check_con);

View File

@ -443,6 +443,45 @@ order by 1, 2;
drop table p1 cascade;
--
-- Test DROP behavior of multiply-defined CHECK constraints
--
create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
create table p1_c1 (f1 int constraint f1_pos CHECK (f1 > 0)) inherits (p1);
alter table p1_c1 drop constraint f1_pos;
alter table p1 drop constraint f1_pos;
\d p1_c1
drop table p1 cascade;
create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
create table p2(f1 int constraint f1_pos CHECK (f1 > 0));
create table p1p2_c1 (f1 int) inherits (p1, p2);
create table p1p2_c2 (f1 int constraint f1_pos CHECK (f1 > 0)) inherits (p1, p2);
alter table p2 drop constraint f1_pos;
alter table p1 drop constraint f1_pos;
\d p1p2_c*
drop table p1, p2 cascade;
create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
create table p1_c1() inherits (p1);
create table p1_c2() inherits (p1);
create table p1_c1c2() inherits (p1_c1, p1_c2);
\d p1_c1c2
alter table p1 drop constraint f1_pos;
\d p1_c1c2
drop table p1 cascade;
create table p1(f1 int constraint f1_pos CHECK (f1 > 0));
create table p1_c1() inherits (p1);
create table p1_c2(constraint f1_pos CHECK (f1 > 0)) inherits (p1);
create table p1_c1c2() inherits (p1_c1, p1_c2, p1);
alter table p1_c2 drop constraint f1_pos;
alter table p1 drop constraint f1_pos;
alter table p1_c1c2 drop constraint f1_pos;
alter table p1_c2 drop constraint f1_pos;
\d p1_c1c2
drop table p1 cascade;
-- Test that a valid child can have not-valid parent, but not vice versa
create table invalid_check_con(f1 int);
create table invalid_check_con_child() inherits(invalid_check_con);