Find as to whether different data types (with and without timezone) and precisions are used in case of registering times in different columns.
Notes
In case of the string_agg function, the line break (br) tag is used as a part of the separator for the better readability in case the query result is displayed in a web browser.
Type
Problem detection (Each row in the result could represent a flaw in the design)
WITH num_cols AS (SELECT table_schema, table_name, column_name, ordinal_position,
CASE WHEN datetime_precision IS NOT NULL THEN data_type || '(' || datetime_precision || ')'
ELSE data_type END AS data_type
FROM INFORMATION_SCHEMA.columns
WHERE data_type~*'time'
AND data_type!~*'timestamp'
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))
SELECT data_type, string_agg(table_schema || '.' || table_name || '.' || column_name, ', ' ORDER BY table_schema, table_name) AS tables, Count(*) AS number_of_columns
FROM num_cols
WHERE (SELECT Count(DISTINCT data_type) AS cnt FROM num_cols)>1
GROUP BY data_type
ORDER BY Count(*) DESC, data_type;
Collections
This query belongs to the following collections:
Name
Description
Find problems automatically
Queries, 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:
Name
Description
Data types
Queries of this category provide information about the data types and their usage.
Inconsistencies
Queries of this catergory provide information about inconsistencies of solving the same problem in different places.
Temporal data
Queries of this category provide information about temporal (time-related) data that is kept in the database.