public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: Alvaro Herrera <[email protected]>
Cc: Tender Wang <[email protected]>
Cc: Alexander Lakhin <[email protected]>
Cc: Jehan-Guillaume de Rorthais <[email protected]>
Cc: [email protected] <[email protected]>
Cc: Guillaume Lelarge <[email protected]>
Subject: Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails
Date: Fri, 08 Nov 2024 10:42:59 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
Alvaro Herrera <[email protected]> writes:
>> Perhaps one more task for me is to figure out a way to get a list of all
>> 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 = 'f' and conparentid = 0 AND
> (SELECT count(*) FROM pg_constraint p2 WHERE conparentid = pg_constraint.oid) <>
> (SELECT count(*)
> FROM pg_inherits
> WHERE inhparent = pg_constraint.conrelid OR inhparent = pg_constraint.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=# SELECT inhrelid::regclass, inhparent::regclass, inhseqno,inhdetachpending from pg_inherits WHERE inhparent = 'clstr_tst'::regclass or inhparent = '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
view thread (6+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox