PostgreSQL

varchar(n) creates arbitrary length limits requiring table rewrites

info
configurationUpdated Mar 4, 2026
Technologies:
How to detect:

varchar(n) provides no performance advantage over text in PostgreSQL (both handled identically), but creates a length constraint that may need changing later. Altering varchar length requires a table rewrite on older PostgreSQL versions. The length limit is often arbitrary (e.g. varchar(255)).

Recommended action:

Use text with CHECK constraints for validation: CREATE TABLE users (username text NOT NULL CHECK (length(username) BETWEEN 3 AND 50), bio text CHECK (length(bio) <= 10000)). CHECK constraints can be added/removed without rewriting the table and support complex validation rules.