The list of all the queries

All supertables

Query goal: Find all the base tables that serve as supertables in the inheritance hierarchies
Notes about the query: The query finds base tables that participate in an inheritance hierarchy and do not have any parent table.
Query type: Sofware measure (Numeric values (software measures) about the database)
Query license: MIT License
Data source: system catalog only
SQL query: Click on query to copy it

WITH tables_in_inheritance_hierarchy AS (SELECT pn.nspname AS parent_schema, p.oid AS parent_oid, p.relname AS parent_table, pi.inhrelid AS child_oid
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
WHERE (pn.nspname='public' OR ap.rolname<>'postgres'))
SELECT parent_schema, parent_table, Count(*) AS number_of_direct_children
FROM tables_in_inheritance_hierarchy AS tih
WHERE NOT EXISTS (SELECT 1
FROM tables_in_inheritance_hierarchy AS tih_check 
WHERE tih.parent_oid=tih_check.child_oid)
GROUP BY parent_schema, parent_table
ORDER BY Count(*) DESC, parent_schema, parent_table;

Collections where the query belongs to

Collection nameCollection description
Find problems about base tablesA selection of queries that return information about the data types, field sizes, default values as well as general structure of base tables. Contains all the types of queries - problem detection, software measure, and general overview
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 .
Find quick numeric overview of the databaseQueries that return numeric values showing mostly the number of different types of database objects in the database

Categories where the query belongs to

Category nameCategory description
Table inheritanceQueries of this category provide information about the inheritance between base tables.

Reference materials for further reading

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

The list of all the queries