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.

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

In 10 seconds

What
Value too long for character varying(n)
What triggers it
Create a table with a varchar(5) column.
The 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.

The fix

What to do right now

The immediate, application-level response to 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');

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

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