Goal The default value of a column should belong to the type of the column. The system shouldn't conduct unnecessary type casts.
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability Medium (Medium number of false-positive results)
License MIT License
Fixing Suggestion Replace default value that is a textual value (has aposthrophes) with a default value that has no apostrophes, i.e., is not a representation of a textual value.
Data Source INFORMATION_SCHEMA only
SQL Query
SELECT A.table_schema, T.table_type, A.table_name , A.column_name, A.data_type, d.domain_default, a.column_default
FROM information_schema.columns A INNER JOIN information_schema.tables T USING (table_schema, table_name)
INNER JOIN information_schema.schemata S ON A.table_schema=S.schema_name
LEFT JOIN information_schema.domains D USING (domain_schema, domain_name)
WHERE (A.table_schema = 'public'
OR S.schema_owner<>'postgres')
AND A.data_type IN ('smallint','integer','bigint','double precision','real','numeric') AND
((D.domain_default LIKE '%::'|| A.data_type AND D.domain_default~'['']') 
OR (A.column_default LIKE '%::'|| A.data_type AND A.column_default~'['']'))
ORDER BY table_type, table_schema, table_name, column_name;

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
Comfortability of database evolutionQueries of this category provide information about the means that influence database evolution.
Data typesQueries of this category provide information about the data types and their usage.
Default valueQueries of this catergory provide information about the use of default values.
PerformanceQueries of this category provide information about indexes in a database.
Validity and completenessQueries of this category provide information about whether database design represents the world (domain) correctly (validity) and whether database design captures all the information about the world (domain) that is correct and relevant (completeness).