From e9b0afef7bf61f614122aeabe16a357158c4303a Mon Sep 17 00:00:00 2001 From: Ivan Vakhrushev Date: Tue, 10 Dec 2024 22:10:31 +0400 Subject: [PATCH] [TABLES_NOT_LINKED_TO_OTHERS] Decide how to handle partitioned tables (#65) --- sql/tables_not_linked_to_others.sql | 1 + sql/tables_without_primary_key.sql | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/tables_not_linked_to_others.sql b/sql/tables_not_linked_to_others.sql index dc9890d..e265b3d 100644 --- a/sql/tables_not_linked_to_others.sql +++ b/sql/tables_not_linked_to_others.sql @@ -47,5 +47,6 @@ from inner join nsp on nsp.oid = pc.relnamespace where pc.relkind in ('r', 'p') and + not pc.relispartition and pc.oid not in (select * from fkeys) order by table_name; diff --git a/sql/tables_without_primary_key.sql b/sql/tables_without_primary_key.sql index b948f91..c52e76d 100644 --- a/sql/tables_without_primary_key.sql +++ b/sql/tables_without_primary_key.sql @@ -13,7 +13,8 @@ from pg_catalog.pg_class pc inner join pg_catalog.pg_namespace nsp on nsp.oid = pc.relnamespace where - pc.relkind = 'r' and + pc.relkind in ('r', 'p') and + /* here we do not filter by pc.relispartition, because very often primary keys are created only for partitions */ pc.oid not in ( select c.conrelid as table_oid from pg_catalog.pg_constraint c