diff options
Diffstat (limited to 'src/test/regress/sql/inherit.sql')
-rw-r--r-- | src/test/regress/sql/inherit.sql | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql index f51c70d6b03..49aae426f3c 100644 --- a/src/test/regress/sql/inherit.sql +++ b/src/test/regress/sql/inherit.sql @@ -468,13 +468,58 @@ alter table p1_c1 add constraint inh_check_constraint1 check (f1 > 0); alter table p1_c1 add constraint inh_check_constraint2 check (f1 < 10); alter table p1 add constraint inh_check_constraint2 check (f1 < 10); -select conrelid::regclass::text as relname, conname, conislocal, coninhcount +alter table p1 add constraint inh_check_constraint3 check (f1 > 0) not enforced; +alter table p1_c1 add constraint inh_check_constraint3 check (f1 > 0) not enforced; + +alter table p1_c1 add constraint inh_check_constraint4 check (f1 < 10) not enforced; +alter table p1 add constraint inh_check_constraint4 check (f1 < 10) not enforced; + +-- allowed to merge enforced constraint with parent's not enforced constraint +alter table p1_c1 add constraint inh_check_constraint5 check (f1 < 10) enforced; +alter table p1 add constraint inh_check_constraint5 check (f1 < 10) not enforced; + +alter table p1 add constraint inh_check_constraint6 check (f1 < 10) not enforced; +alter table p1_c1 add constraint inh_check_constraint6 check (f1 < 10) enforced; + +create table p1_c2(f1 int constraint inh_check_constraint4 check (f1 < 10)) inherits(p1); + +-- but reverse is not allowed +alter table p1_c1 add constraint inh_check_constraint7 check (f1 < 10) not enforced; +alter table p1 add constraint inh_check_constraint7 check (f1 < 10) enforced; + +alter table p1 add constraint inh_check_constraint8 check (f1 < 10) enforced; +alter table p1_c1 add constraint inh_check_constraint8 check (f1 < 10) not enforced; + +create table p1_fail(f1 int constraint inh_check_constraint2 check (f1 < 10) not enforced) inherits(p1); + +-- constraints with different enforceability can be merged by marking them as ENFORCED +create table p1_c3() inherits(p1, p1_c1); + +-- but not allowed if the child constraint is explicitly asked to be NOT ENFORCED +create table p1_fail(f1 int constraint inh_check_constraint6 check (f1 < 10) not enforced) inherits(p1, p1_c1); + +select conrelid::regclass::text as relname, conname, conislocal, coninhcount, conenforced from pg_constraint where conname like 'inh\_check\_constraint%' order by 1, 2; drop table p1 cascade; -- +-- Similarly, check the merging of existing constraints; a parent constraint +-- marked as NOT ENFORCED can merge with an ENFORCED child constraint, but the +-- reverse is not allowed. +-- +create table p1(f1 int constraint p1_a_check check (f1 > 0) not enforced); +create table p1_c1(f1 int constraint p1_a_check check (f1 > 0) enforced); +alter table p1_c1 inherit p1; +drop table p1 cascade; + +create table p1(f1 int constraint p1_a_check check (f1 > 0) enforced); +create table p1_c1(f1 int constraint p1_a_check check (f1 > 0) not enforced); +alter table p1_c1 inherit p1; +drop table p1, p1_c1; + +-- -- Test DROP behavior of multiply-defined CHECK constraints -- create table p1(f1 int constraint f1_pos CHECK (f1 > 0)); |