| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
| Cc: | Tender Wang <tndrwang(at)gmail(dot)com>, Alexander Lakhin <exclusion(at)gmail(dot)com>, Jehan-Guillaume de Rorthais <jgdr(at)dalibo(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Guillaume Lelarge <guillaume(at)lelarge(dot)info> |
| Subject: | Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails |
| Date: | 2024-11-08 15:42:59 |
| Message-ID: | 3645003.1731080579@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2024-11-08 16:26:11 | Re: not null constraints, again |
| Previous Message | Tom Lane | 2024-11-08 15:06:44 | Re: Fix small typo, use InvalidRelFileNumber instead of InvalidOid |