Hello
+ * During recursion, another parent outside this ALTER may still enforce
+ * the same constraint. In that case, keep the child constraint ENFORCED
+ * so that its merged enforceability still reflects the remaining
enforced
+ * parent.
+ */
+ if (!cmdcon->is_enforced)
+ {
This means once is_enforced is set to true, it will never be
rechecked. See the following example which showcases an issue with
this:
create table g(a int constraint k check(a > 0) enforced);
create table o(a int constraint k check(a > 0) enforced);
create table s1() inherits(g);
create table s2() inherits(g, o);
create table s3() inherits(g);
alter table g alter constraint k not enforced;
select conrelid::regclass as tbl, conenforced
from pg_constraint
where conname = 'k' and contype = 'c'
order by conrelid::regclass::text collate "C";
insert into s1 values (-1);
insert into s3 values (-1); -- bug: ERRORs out, but shouldn't