The list of all the queries

The proportion of using different integer types as types of base table columns

Query 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.
Query type: Sofware measure (Numeric values (software measures) about the database)
Query license: MIT License
Data source: INFORMATION_SCHEMA only
SQL query: Click on query to copy it

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 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
Data typesQueries of this category provide information about the data types and their usage.

The list of all the queries