WITH number_of_cols AS (SELECT table_schema, table_name, table_type, Count(c.table_schema) AS number_of_columns
FROM INFORMATION_SCHEMA.tables AS t LEFT JOIN information_schema.columns AS c USING (table_schema, table_name)
WHERE t.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)
GROUP BY table_schema, table_name, table_type
UNION SELECT nspname, relname, 'MATERIALIZED VIEW' AS table_type, Count(*) AS number_of_columns
FROM pg_class INNER JOIN pg_namespace ON pg_class.relnamespace=pg_namespace.oid
LEFT JOIN pg_attribute ON pg_class.oid=pg_attribute.attrelid
WHERE relkind = 'm' AND attnum>=1 AND
nspname NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)
GROUP BY nspname, relname)
SELECT table_type, table_schema, table_name, number_of_columns
FROM number_of_cols
WHERE number_of_columns<=1
ORDER BY table_schema, table_type, table_name, number_of_columns DESC;
Collections
This query belongs to the following collections:
Name
Description
Find problems about base tables
A 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 overview
Queries 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:
Name
Description
Structure of base tables
Queries of this category provide information about the structuring of base tables at the database conceptual level
Validity and completeness
Queries 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).