ALTER CONSTRAINT on a partitioned FK isn't working
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2020-12-07T19:33:53Z
Lists: pgsql-bugs
I reproduced the problem shown in [1]: --- snip --- drop table if exists pt, ref; create table pt(f1 int, f2 int, f3 int, primary key(f1,f2)) partition by list(f1); create table pt1 partition of pt for values in (1); create table pt2 partition of pt for values in (2); create table ref(f1 int, f2 int, f3 int) partition by list(f1); create table ref1 partition of ref for values in (1); create table ref2 partition of ref for values in (2); alter table ref add foreign key(f1,f2) references pt; alter table ref alter constraint ref_f1_f2_fkey deferrable initially deferred; insert into pt values(1,2,3); insert into ref values(1,2,3); delete from pt; -- expected to fail begin; delete from pt; -- this should work, but does not delete from ref; abort; --- snip --- But if you create the FK in one step with alter table ref add foreign key(f1,f2) references pt deferrable initially deferred; then everything behaves as expected. So something is broken about propagating deferred-ness to partition triggers in an ALTER CONSTRAINT. Oddly, it *looks* like it worked if you examine the child tables with "\d+". I surmise that ALTER CONSTRAINT fixes whatever catalog fields psql looks at, but there's some other fields that also need to be updated and aren't being. regards, tom lane [1] https://www.postgresql.org/message-id/flat/75fe0761-a291-86a9-c8d8-4906da077469%40gmail.com
Commits
-
Have ALTER CONSTRAINT recurse on partitioned tables
- 6f70d7ca1d19 14.0 landed
- abce26c9eb95 12.7 landed
- a25b98d2cf38 11.12 landed
- 923c13520f1b 13.3 landed
-
Fix OID passed to object-alter hook during ALTER CONSTRAINT
- e798d095da3a 14.0 landed
- 91a6b3862fef 13.3 landed
- 72fabd4bfb5a 12.7 landed