Goal Find instances of multiple inheriance of base tables. Make sure that multiple inheritance is indeed needed.
Type General (Overview of some aspect of the database.)
License MIT License
Data Source system catalog only
SQL Query
WITH tables_in_inheritance_hierarchy AS (SELECT pn.nspname AS parent_schema, p.relname AS parent_table, pc.nspname AS child_schema, c.relname AS child_table
FROM pg_inherits pi INNER JOIN pg_class p ON pi.inhparent=p.oid
INNER JOIN pg_namespace pn ON p.relnamespace=pn.oid
INNER JOIN pg_authid AS ap ON pn.nspowner=ap.oid
INNER JOIN pg_class c ON pi.inhrelid=c.oid
INNER JOIN pg_namespace pc ON c.relnamespace=pc.oid
INNER JOIN pg_authid AS ac ON pc.nspowner=ac.oid
WHERE (pn.nspname='public' OR ap.rolname<>'postgres') 
AND (pc.nspname='public' OR ac.rolname<>'postgres'))
SELECT child_schema, child_table, string_agg(parent_schema || '.' || parent_table, ',
' ORDER BY parent_schema, parent_table) AS parents, Count(*) AS number_of_parents FROM tables_in_inheritance_hierarchy GROUP BY child_schema, child_table HAVING Count(*)>1 ORDER BY Count(*) DESC, child_schema, child_table;
Collections

This query belongs to the following collections:

NameDescription
Find problems by overviewQueries that results point to different aspects of database that might have problems. A human reviewer has to decide based on the results as to whether there are problems or not .
Categories

This query is classified under the following categories:

NameDescription
Comfortability of database evolutionQueries of this category provide information about the means that influence database evolution.
Comfortability of data managementQueries of this category provide information about the means that have been used to make the use or management of database more comfortable and thus, more efficient.
Table inheritanceQueries of this category provide information about the inheritance between base tables.

Further reading and related materials:

Reference
https://www.postgresql.org/docs/current/tutorial-inheritance.html