SQLSTATE 22001Severity mediumLab verified

Incident brief

Value too long for character varying(n)

A string was too long to fit in a length-limited column. PostgreSQL rejects it, except in one narrow case the manual calls out by name.

What lands in your log

ERROR: value too long for type character varying(5)

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What triggers it
Create a table with a varchar(5) column.
Fix
Widen the column if longer values are genuinely valid data.
Proof
Reproduced on PostgreSQL 16.14 → Inserting 'toolongname' (11 characters) into a varchar(5) column was rejected with SQLSTATE 22001. No row was stored.

Fix

What to do right now

Application-level steps for this error.

  • Widen the column if longer values are genuinely valid data.
  • Validate or trim the string length in the application before inserting.
  • Use text instead of a length-limited type when there's no real limit to enforce.
Fix SQL
-- widen the column so a legitimately longer value fits
ALTER TABLE growth.beta_signups ALTER COLUMN username TYPE varchar(20);
INSERT INTO growth.beta_signups (id, username) VALUES (4, 'toolongname');

Runbook to fix this

The runbook for this incident

Full step-by-step fixes for the condition behind this error: the diagnosis, the exact SQL, and output captured in the lab.

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Verification scope
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops