Query goal: | Find as to whether different data types (with and without timezone) and precisions are used in case of registering times in different columns. |
Notes about the query: | 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. |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | Low (Many false-positive results) |
Query license: | MIT License |
Data source: | INFORMATION_SCHEMA only |
SQL query: | Click on query to copy it
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, ',<br>' 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; |
Collection name | Collection 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 . |
Category name | Category 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. |