Skip to content
Sarj Code Standards

prefer-text-over-varchar

VARCHAR(n) — use TEXT (+ CHECK length if needed).

Why

PostgreSQL gives VARCHAR(n) no storage or performance advantage, while its length cap obscures a business constraint.

Fix

Use TEXT and express a real maximum length with an explicit CHECK constraint when needed.

Examples

Before — flagged Length-limited VARCHAR column
migrations/001_users.sql
CREATE TABLE users (name VARCHAR(255) NOT NULL);
After — preferred Text column with an explicit length constraint
migrations/001_users.sql
CREATE TABLE users (
name TEXT NOT NULL CHECK (char_length(name) <= 255)
);
Before — flagged A quoted builtin still declares a bounded VARCHAR column
migrations/001_users.sql
CREATE TABLE users (name "varchar" (255));
After — preferred A schema-qualified function keeps its own contract
queries/name.sql
SELECT
app.varchar (255);