Goal Find all the default values of base table, view, and foreign table columns that are expressions invoking a function that returns a timestamp. Do it only if there are different expressions, i.e., there could be possible inconsistencies.
Notes The query excludes default value expressions like date_trunc('minute'::text, now()) and 'infinity'::timestamp without time zone
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability Low (Many false-positive results)
License MIT License
Data Source INFORMATION_SCHEMA only
SQL Query
SELECT c.table_schema, t.table_type, c.table_name, c.column_name,  c.data_type, c.domain_schema, c.domain_name, coalesce(c.column_default, domain_default) AS default_value,
CASE WHEN c.column_default IS NOT NULL THEN 'Column default' ELSE 'Domain default' END AS default_type
FROM information_schema.columns AS c LEFT JOIN information_schema.domains d USING (domain_schema, domain_name)
INNER JOIN INFORMATION_SCHEMA.tables AS t  USING (table_schema, table_name)
WHERE c.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) 
AND (column_default IS NOT NULL OR domain_default IS NOT NULL)
AND coalesce(c.column_default, domain_default)~*'(timestamp|now())'
AND (SELECT Count(DISTINCT coalesce(c.column_default, domain_default)) AS cnt
FROM information_schema.columns AS c LEFT JOIN information_schema.domains d USING (domain_schema, domain_name)
INNER JOIN INFORMATION_SCHEMA.tables AS t  USING (table_schema, table_name)
WHERE c.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) 
AND (column_default IS NOT NULL OR domain_default IS NOT NULL)
AND coalesce(c.column_default, domain_default)~*'(timestamp|now())'
AND coalesce(c.column_default, domain_default)!~*'(date_part|infinity|interval)')>1
ORDER BY t.table_type, c.table_schema, c.table_name, c.ordinal_position;

Collections

This query belongs to the following collections:

NameDescription
Find problems automaticallyQueries, 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:

NameDescription
Default valueQueries of this catergory provide information about the use of default values.
InconsistenciesQueries of this catergory provide information about inconsistencies of solving the same problem in different places.
Temporal dataQueries of this category provide information about temporal (time-related) data that is kept in the database.