The list of all the queries

Small tables

Query goal: Find tables that have one column or zero columns.
Query type: General (Overview of some aspect of the database.)
Query license: MIT License
Data source: INFORMATION_SCHEMA+system catalog
SQL query: Click on query to copy it

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

Categories where the query belongs to

Category nameCategory description
Structure of base tablesQueries of this category provide information about the structuring of base tables at the database conceptual level
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