Goal Find as to whether some columns with the type Boolean start with a prefix ("is", "has", "can", "on") and some do not.
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 Make naming consistent.
Data Source INFORMATION_SCHEMA+system catalog
SQL Query
WITH columns AS (SELECT nspname AS table_schema, relname AS table_name, 
CASE WHEN relkind='r' THEN 'BASE TABLE'
WHEN relkind='v' THEN 'VIEW'
WHEN relkind='m' THEN 'MATERIALIZED VIEW'
WHEN relkind='f' THEN 'FOREIGN TABLE'
WHEN relkind='p' THEN 'PARTITIONED TABLE'
END AS table_type, 
attname AS column_name,
pg_type.typname AS column_type,
domain_type.typname AS column_domain_type
FROM pg_class INNER JOIN pg_namespace ON pg_class.relnamespace=pg_namespace.oid
INNER JOIN pg_attribute ON pg_class.oid=pg_attribute.attrelid
INNER JOIN pg_type ON pg_attribute.atttypid =pg_type.oid
LEFT JOIN pg_type AS domain_type ON domain_type.oid=pg_type.typbasetype
WHERE attnum>=1 
AND relkind IN ('r','v','m','f','p')
AND nspname NOT IN (SELECT schema_name
FROM INFORMATION_SCHEMA.schemata
WHERE schema_name<>'public' AND
schema_owner='postgres' AND schema_name IS NOT NULL)),
boolean_columns AS (SELECT table_schema, table_name, table_type, column_name, column_type, column_domain_type
FROM columns
WHERE (column_type~*'bool'
OR column_domain_type~*'bool'))
SELECT table_schema, table_name, table_type, column_name, column_type, column_domain_type
FROM boolean_columns
WHERE EXISTS (SELECT * FROM boolean_columns WHERE column_name~*'^(is|has|can|on)[_]*')
AND EXISTS (SELECT * FROM boolean_columns WHERE column_name!~*'^(is|has|can|on)[_]*')
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
Boolean dataQueries of this category provide information about truth-values data that is kept in the database.
Comfortability of data managementQueries of this category provide information about the means that have been used to make the use or management of database more comfortable and thus, more efficient.
Data typesQueries of this category provide information about the data types and their usage.
NamingQueries of this category provide information about the style of naming.