From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | ALTER CONSTRAINT on a partitioned FK isn't working |
Date: | 2020-12-07 19:33:53 |
Message-ID: | 3144850.1607369633@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2020-12-07 23:34:14 | Re: ALTER CONSTRAINT on a partitioned FK isn't working |
Previous Message | PG Bug reporting form | 2020-12-07 15:06:43 | BUG #16766: PGAdmin4 Browser : Autocomplete not working |