The list of all the queries

CHAR columns have a default value that length is shorter from the character maximum length of the column

Query goal: Choose a suitable data type, field size, and default value. If the default value is shorter from the character maximum length, then spaces will be added to the end of the registered value.
Query type: Problem detection (Each row in the result could represent a flaw in the design)
Query reliability: High (Few or no false-positive results)
Query license: MIT License
Fixing suggestion: Perhaps the column should have type VARCHAR.
Data source: INFORMATION_SCHEMA only
SQL query: Click on query to copy it

WITH defaults AS (SELECT c.table_schema, t.table_type, c.table_name, c.column_name, CASE WHEN column_default IS NOT NULL THEN 'COLUMN' ELSE 'DOMAIN' END AS object_type,  c.data_type, c.character_maximum_length, coalesce(c.column_default, domain_default) AS def_value
FROM information_schema.columns AS c LEFT JOIN information_schema.domains d ON c.domain_schema=d.domain_schema AND c.domain_name=d.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 c.data_type='character' 
AND coalesce(c.column_default, domain_default) LIKE '%::bpchar'
AND (column_default IS NOT NULL OR domain_default IS NOT NULL)
ORDER BY c.table_schema, c.table_name, c.ordinal_position)
SELECT table_schema, table_type, table_name, column_name, character_maximum_length, data_type, def_value, object_type
FROM defaults
WHERE char_length(trim(substring(def_value,'[''][^'']*['']'),'''')) <character_maximum_length
ORDER BY table_type, table_schema, table_name;

Collections where the query belongs to

Collection nameCollection description
Find problems about base tablesA selection of queries that return information about the data types, field sizes, default values as well as general structure of base tables. Contains all the types of queries - problem detection, software measure, and general overview
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 where the query belongs to

Category nameCategory description
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.
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).

The list of all the queries