Content-Length: 265231 | pFad | http://github.com/postgres/postgres/commit/4620cd9c1c80984419ff135bfc1a9c79ff16ab6f

76 Fix broken-FK-detection query in release notes · postgres/postgres@4620cd9 · GitHub
Skip to content

Commit 4620cd9

Browse files
author
Álvaro Herrera
committed
Fix broken-FK-detection query in release notes
Commits 53af949 and 2d5fe51 fixed a number of problems with foreign keys that reference partitioned tables, and a query to detect already broken FKs was supplied with the release notes for 17.1, 16.5, 15.9, 14.14, 13.17. However, that query has a bug that causes it to wrongly report self-referential foreign keys even when they are correct, so if the user was to drop and rebuild the FKs as indicated, the query would continue to report them as needing to be repaired. Here we fix the query to not have that problem. Reported-by: Paul Foerster <paul.foerster@gmail.com> Discussion: https://postgr.es/m/5456A1D0-CD47-4315-9C65-71B27E7A2906@gmail.com Backpatch-through: 13-17
1 parent 09c9ae8 commit 4620cd9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

doc/src/sgml/release-15.sgml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,10 +2750,14 @@ FROM pg_catalog.pg_constraint c
27502750
WHERE contype = 'f' AND conparentid = 0 AND
27512751
(SELECT count(*) FROM pg_catalog.pg_constraint c2
27522752
WHERE c2.conparentid = c.oid) &lt;&gt;
2753-
(SELECT count(*) FROM pg_catalog.pg_inherits i
2753+
((SELECT count(*) FROM pg_catalog.pg_inherits i
27542754
WHERE (i.inhparent = c.conrelid OR i.inhparent = c.confrelid) AND
27552755
EXISTS (SELECT 1 FROM pg_catalog.pg_partitioned_table
2756-
WHERE partrelid = i.inhparent));
2756+
WHERE partrelid = i.inhparent)) +
2757+
CASE WHEN pg_catalog.pg_partition_root(conrelid) = confrelid THEN
2758+
(SELECT count(*) FROM pg_catalog.pg_partition_tree(confrelid)
2759+
WHERE level = 1)
2760+
ELSE 0 END);
27572761
</programlisting>
27582762
Since it is possible that one or more of the <literal>ADD
27592763
CONSTRAINT</literal> steps will fail, you should save the query's

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgres/postgres/commit/4620cd9c1c80984419ff135bfc1a9c79ff16ab6f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy