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 1t9R8k-00AAbB-K0 for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Nov 2024 15:43:13 +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 1t9R8h-00Ad84-Ja for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Nov 2024 15:43: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 1t9R8h-00Ad7w-9s for pgsql-hackers@lists.postgresql.org; Fri, 08 Nov 2024 15:43:11 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t9R8d-000s3j-KR for pgsql-hackers@postgresql.org; Fri, 08 Nov 2024 15:43:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4A8FgxPo3645004; Fri, 8 Nov 2024 10:43:00 -0500 From: Tom Lane To: Alvaro Herrera cc: Tender Wang , Alexander Lakhin , Jehan-Guillaume de Rorthais , "pgsql-hackers@postgresql.org" , Guillaume Lelarge Subject: Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails In-reply-to: <202411061753.ufb6tepg5cr4@alvherre.pgsql> References: <202411061753.ufb6tepg5cr4@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Wed, 06 Nov 2024 18:53:07 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3645002.1731080579.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 08 Nov 2024 10:42:59 -0500 Message-ID: <3645003.1731080579@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera writes: >> Perhaps one more task for me is to figure out a way to get a list of al= l >> the constraints that are broken because of this ... let me see if I can >> figure that out. > It's gotta be something like this, > SELECT conrelid::regclass AS "constrained table", > conname as constraint, confrelid::regclass AS "references" > FROM pg_constraint > WHERE contype =3D 'f' and conparentid =3D 0 AND > (SELECT count(*) FROM pg_constraint p2 WHERE conparentid =3D pg_const= raint.oid) <> > (SELECT count(*) > FROM pg_inherits > WHERE inhparent =3D pg_constraint.conrelid OR inhparent =3D pg_cons= traint.confrelid); Hmm ... interestingly, if I run this in HEAD's regression database, I get constrained table | constraint | references = -------------------+---------------+------------- clstr_tst | clstr_tst_con | clstr_tst_s (1 row) Digging a bit deeper, the sub-select for conparentid finds no rows, but the sub-select on pg_inherits finds regression=3D# SELECT inhrelid::regclass, inhparent::regclass, inhseqno,in= hdetachpending from pg_inherits WHERE inhparent =3D 'clstr_tst'::regclass = or inhparent =3D 'clstr_tst_s'::regclass; inhrelid | inhparent | inhseqno | inhdetachpending = ---------------+-----------+----------+------------------ clstr_tst_inh | clstr_tst | 1 | f (1 row) So it looks like this query needs a guard to make it ignore constraints on traditional-inheritance tables. regards, tom lane