ALTER CONSTRAINT on a partitioned FK isn't working - Mailing list pgsql-bugs

From Tom Lane
Subject ALTER CONSTRAINT on a partitioned FK isn't working
Date
Msg-id 3144850.1607369633@sss.pgh.pa.us
Whole thread Raw
Responses Re: ALTER CONSTRAINT on a partitioned FK isn't working
Re: ALTER CONSTRAINT on a partitioned FK isn't working
List 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



pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #16766: PGAdmin4 Browser : Autocomplete not working
Next
From: Alvaro Herrera
Date:
Subject: Re: ALTER CONSTRAINT on a partitioned FK isn't working