Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzZ8K-003eb1-BX for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Apr 2025 10:46:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tzZ8G-000lnc-DP for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Apr 2025 10:46:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzZ8G-000lnT-5T for pgsql-bugs@lists.postgresql.org; Tue, 01 Apr 2025 10:46:12 +0000 Received: from mout-p-103.mailbox.org ([2001:67c:2050:0:465::103]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tzZ8B-002jce-0a for pgsql-bugs@lists.postgresql.org; Tue, 01 Apr 2025 10:46:11 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4ZRl6404PXz9v4h; Tue, 1 Apr 2025 12:46:04 +0200 (CEST) Date: Tue, 1 Apr 2025 12:46:02 +0200 From: Christoph Berg To: Luca Vallisa Cc: pgsql-bugs@lists.postgresql.org Subject: Re: Self referential foreign keys in partitioned table not working as expected Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4ZRl6404PXz9v4h List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Re: Luca Vallisa > The provided version throws an error. Ok, I can confirm this. This throws an error like it should: 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) ); insert into test values (1, 1, null), (1, 2, 1); delete from test where (id_1, id_2) = (1, 1); 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); Christoph