The list of all the queries

Base tables that have only the surrogate key and do not have any other column

Query goal: Do not create unnecessary tables. If a table has cardinality 1 (one column), then most probably the values in this column should not be system generated unique values.
Notes about the query: The query takes into account both external and internal (are created as the result of declaring a column as the identity column) sequence generators. The query takes into account a possibility that a column may be associated with a sequence generator through a domain.
Query type: Problem detection (Each row in the result could represent a flaw in the design)
Query reliability: High (Few or no false-positive results)
Query license: MIT License
Fixing suggestion: Drop the column association with the sequence generator.
Data source: INFORMATION_SCHEMA only
SQL query: Click on query to copy it

WITH tables_with_a_surrogate AS (SELECT table_schema, table_name 
FROM ((information_schema.table_constraints tc
INNER JOIN information_schema.constraint_column_usage cu
USING (table_schema, table_name, constraint_name))
INNER JOIN information_schema.columns c
USING (table_schema, table_name, column_name))
LEFT JOIN information_schema.domains d USING (domain_schema, domain_name)
INNER JOIN information_schema.schemata s
ON tc.table_schema=s.schema_name
WHERE tc.constraint_type IN ('PRIMARY KEY','UNIQUE') AND
(coalesce (c.column_default, d.domain_default) ILIKE '%nextval%'  OR C.is_identity='YES')
AND (tc.table_schema = 'public'
OR S.schema_owner<>'postgres'))
SELECT table_schema, table_name 
FROM tables_with_a_surrogate AS tws
WHERE  (SELECT Count(*) AS cnt FROM information_schema.columns AS c WHERE c.table_schema=tws.table_schema AND c.table_name=tws.table_name)=1
ORDER BY table_schema, table_name ;

Collections where the query belongs to

Collection nameCollection description
Find problems automaticallyQueries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .

Categories where the query belongs to

Category nameCategory description
Default valueQueries of this catergory provide information about the use of default values.
Sequence generatorsQueries of this category provide information about sequence generators and their usage.
UniquenessQueries of this category provide information about uniqueness constraints (PRIMARY KEY, UNIQUE, EXCLUDE) as well as unique indexes.
Validity and completenessQueries of this category provide information about whether database design represents the world (domain) correctly (validity) and whether database design captures all the information about the world (domain) that is correct and relevant (completeness).

The list of all the queries