Goal Find the number of base table columns that use different integer types (SMALLINT, INTEGER, BIGINT) and their proportion from the overall set of columns that use an integer type.
Type Sofware measure (Numeric values (software measures) about the database)
License MIT License
Data Source INFORMATION_SCHEMA only
SQL Query
SELECT 
Count(*) FILTER (WHERE data_type='smallint') AS nr_of_smallint_columns,
Round((Count(*) FILTER (WHERE data_type='smallint'))::numeric*100/Count(*)::numeric,1) AS percentage_of_smallint_columns,
Count(*) FILTER (WHERE data_type='integer') AS nr_of_integer_columns,
Round((Count(*) FILTER (WHERE data_type='integer'))::numeric*100/Count(*)::numeric,1) AS percentage_of_integer_columns,
Count(*) FILTER (WHERE data_type='bigint') AS nr_of_bigint_columns,
Round((Count(*) FILTER (WHERE data_type='bigint'))::numeric*100/Count(*)::numeric,1) AS percentage_of_bigint_columns
FROM INFORMATION_SCHEMA.columns
WHERE data_type IN ('smallint', 'integer', 'bigint') AND 
(table_schema, table_name) IN (SELECT table_schema, table_name
FROM INFORMATION_SCHEMA.tables WHERE table_type='BASE TABLE') AND 
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);

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

This query is classified under the following categories:

NameDescription
Data typesQueries of this category provide information about the data types and their usage.