Re: Self referential foreign keys in partitioned table not working as expected

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: Christoph Berg <myon(at)debian(dot)org>
Cc: Luca Vallisa <luca(dot)vallisa(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Self referential foreign keys in partitioned table not working as expected
Date: 2025-07-23 09:27:04
Message-ID: 202507230927.jnoadaq5v62v@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On 2025-Apr-01, Christoph Berg wrote:

> Re: Luca Vallisa
> > The provided version throws an error.
>
> Ok, I can confirm this.

> On a partitioned table, it does not throw the error:
>
> create table test (
> id_1 int4 not null,
> id_2 int4 not null,
> parent_id_2 int4 null,
> primary key (id_1, id_2),
> foreign key (id_1, parent_id_2) references test (id_1, id_2)
> ) partition by list (id_1);
> create table test_1 partition of test for values in (1);
> insert into test values (1, 1, null), (1, 2, 1);
> delete from test where (id_1, id_2) = (1, 1);

FWIW I didn't give closure on this thread, but AFAICT this is the same
bug that was reported in
https://postgr.es/m/18156-a44bc7096f0683e6@postgresql.org
and
https://postgr.es/m/CAECtzeWHCA+6tTcm2Oh2+g7fURUJpLZb-=pRXgeWJ-Pi+VU=_w@mail.gmail.com

That was fixed a couple of months ago. The above script throws an error
as it should.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-07-23 10:00:55 BUG #18995: Building with GCC 14 fails: incompatible pointer struct pam_message
Previous Message vignesh C 2025-07-23 09:24:49 Re: BUG #18897: Logical replication conflict after using pg_createsubscriber under heavy load

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2025-07-23 10:01:24 RE: 024_add_drop_pub.pl might fail due to deadlock
Previous Message Amit Kapila 2025-07-23 09:26:57 Re: 024_add_drop_pub.pl might fail due to deadlock