String Data Right Truncation — SQLSTATE 22001
SQLSTATE 22001 condition string_data_right_truncation class 22 — Data Exception severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 29 May 2025 · Reproduced live with the SQL on this page.
! Symptoms Free
A string value is too long for the target character column.
- The error is written to the server log and returned to the client carrying
SQLSTATE 22001. - Any driver (libpq, JDBC, psycopg, npgsql, pgx) surfaces this code in its error object so you can branch on it programmatically.
- PL/pgSQL can trap it by name:
EXCEPTION WHEN string_data_right_truncation THEN.
1 Environment & reproduce Free
Severity: ERROR | PostgreSQL versions: 12, 13, 14, 15, 16, 17
Reproduce with the exact statement and read the full message in the server log (raise log_min_messages / set log_min_error_statement for more context).
? Root cause Free
The value exceeds the declared length of a varchar(n) or char(n) column or cast.
Common causes:
- Inserting or updating text longer than the column width.
- An explicit cast to a too-small
varchar(n). - Multibyte characters making the string longer than expected.
3 Recovery & verify Free
Steps to resolve 22001:
- Widen the column:
ALTER TABLE t ALTER COLUMN c TYPE varchar(NNN);, or usetextfor no limit. - Validate or trim input length in the application before writing.
- If truncation is acceptable, apply it explicitly with
left(value, n).
Reference: PostgreSQL error codes — Class 22 (Data Exception).