Goal Find domain CHECK constraints that have a too generic name - for instance, the name contains word "data" ) or the name is an abbreviation of the constraint type name (for instance, "chk" or "chk1").
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability High (Few or no false-positive results)
License MIT License
Fixing Suggestion Rename the constraints.
Data Source INFORMATION_SCHEMA only
SQL Query
SELECT
domain_schema, 
domain_name,
constraint_name AS suspected_constraint_name 
FROM INFORMATION_SCHEMA.domain_constraints
WHERE domain_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 ((constraint_name~*'(andmed|_data|info|veerg|column|kitsendus|piirang|constraint|restriction)' 
AND constraint_name!~*'database')
OR constraint_name~*'^(_){0,1}(ck|chk)(_|[[:digit:]])*$')
ORDER BY domain_schema, domain_name, constraint_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
CHECK constraintsQueries of this category provide information about CHECK constraints.
DomainsQueries of this category provide information about reusable specifications of column properties.
NamingQueries of this category provide information about the style of naming.