summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÁlvaro Herrera <alvherre@kurilemu.de>2025-05-30 16:18:18 +0200
committerÁlvaro Herrera <alvherre@kurilemu.de>2025-05-30 16:18:18 +0200
commit3e75313c2beaf1905bc47623902e0983fb731f8a (patch)
tree94ab4d9a7b43e3743e1fc7d54e6db65757fc2ec1
parente7d3d4ed412e5212c081d52fa3a1a3c37c601970 (diff)
Fix broken-FK-detection query in release notes
Commits 53af9491a043 and 2d5fe514052a 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
-rw-r--r--doc/src/sgml/release-13.sgml8
1 files changed, 6 insertions, 2 deletions
diff --git a/doc/src/sgml/release-13.sgml b/doc/src/sgml/release-13.sgml
index 2bc1476d956..ea92ac288e5 100644
--- a/doc/src/sgml/release-13.sgml
+++ b/doc/src/sgml/release-13.sgml
@@ -2426,10 +2426,14 @@ FROM pg_catalog.pg_constraint c
WHERE contype = 'f' AND conparentid = 0 AND
(SELECT count(*) FROM pg_catalog.pg_constraint c2
WHERE c2.conparentid = c.oid) &lt;&gt;
- (SELECT count(*) FROM pg_catalog.pg_inherits i
+ ((SELECT count(*) FROM pg_catalog.pg_inherits i
WHERE (i.inhparent = c.conrelid OR i.inhparent = c.confrelid) AND
EXISTS (SELECT 1 FROM pg_catalog.pg_partitioned_table
- WHERE partrelid = i.inhparent));
+ WHERE partrelid = i.inhparent)) +
+ CASE WHEN pg_catalog.pg_partition_root(conrelid) = confrelid THEN
+ (SELECT count(*) FROM pg_catalog.pg_partition_tree(confrelid)
+ WHERE level = 1)
+ ELSE 0 END);
</programlisting>
Since it is possible that one or more of the <literal>ADD
CONSTRAINT</literal> steps will fail, you should save the query's