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 1tzYhb-003ZkB-DX for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Apr 2025 10:18:39 +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 1tzYha-000Sds-1h for pgsql-bugs@arkaria.postgresql.org; Tue, 01 Apr 2025 10:18:38 +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 1tzYhZ-000Sdk-PT for pgsql-bugs@lists.postgresql.org; Tue, 01 Apr 2025 10:18:37 +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 1tzYhX-002jPC-1m for pgsql-bugs@lists.postgresql.org; Tue, 01 Apr 2025 10:18:37 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (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 4ZRkVH2RK2z9v8F; Tue, 1 Apr 2025 12:18:31 +0200 (CEST) Date: Tue, 1 Apr 2025 12:18:30 +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: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Re: Luca Vallisa > create table test ( > id_1 int4 not null, > id_2 int4 not null, > parent_id_1 int4 null, > primary key (id_1, id_2), > foreign key (parent_id_1, id_2) references test(id_1, id_2) > ) partition by list(id_1); > > insert into test values (1, 1, null), (1, 2, 1); Multi-column foreign keys where one column is NULL effectively disable the FK, this is not specific to partitioned tables. They works as designed, but best avoid them. Christoph