char(n) pads with spaces causing comparison and storage issues
warningconfigurationUpdated Mar 4, 2026
Technologies:
How to detect:
char(n) pads values with trailing spaces to fill declared length, wasting storage and causing confusing comparison behavior where trailing spaces may or may not be significant. PostgreSQL stores char(n) and text identically internally, so there is zero performance benefit from char(n).
Recommended action:
Use text for all string columns: CREATE TABLE customers (name text NOT NULL, email text NOT NULL). For fixed-length identifiers needing validation, use text with CHECK constraint: CREATE TABLE countries (code text CHECK (code ~ '^[A-Z]{3}$')).