Goal Find base tables where all the columns have a default value.
Notes The query also considers a possibility that the default value is associated with a column through a domain.
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability Low (Many false-positive results)
License MIT License
Fixing Suggestion Perhaps in some cases the default value is not needed and should be dropped.
Data Source INFORMATION_SCHEMA only
SQL Query
WITH cols AS (SELECT c.table_schema, c.table_name, c.column_name,  coalesce(c.column_default, domain_default) AS default_value, c.ordinal_position
FROM information_schema.columns AS c LEFT JOIN information_schema.domains d USING (domain_schema, domain_name)
INNER JOIN INFORMATION_SCHEMA.tables AS t  USING (table_schema, table_name)
WHERE c.table_schema NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL) 
AND t.table_type='BASE TABLE')
SELECT table_schema, table_name, Count(*) AS nr_of_columns, string_agg(column_name || '.' || default_value, ';
' ORDER BY ordinal_position) AS defaults FROM cols GROUP BY table_schema, table_name HAVING Count(*)=Count(*) FILTER (WHERE default_value IS NOT NULL) ORDER BY table_schema, table_name;
Collections

This query belongs to the following collections:

NameDescription
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 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

This query is classified under the following categories:

NameDescription
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.
Default valueQueries of this catergory provide information about the use of default values.