PostgreSQL Error 22001: String Data Right Truncation

PostgreSQL error 22001 (String Data Right Truncation) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

SQLSTATE 22001 PostgreSQL Last verified 2026-08-19

Quick Answer

Check the column's defined length with \d table or information_schema. If that does not apply, widen the column with ALTER TABLE ... TYPE varchar(N) or use TEXT — the full checklist is below.

Error Code

SQLSTATE: 22001
Official name: String Data Right Truncation
Service: PostgreSQL

What does this error mean?

A string value was too long for the column's character type and was truncated, which is not allowed.

Common Causes

How to Fix

  1. Check the column's defined length with \d table or information_schema
  2. Widen the column with ALTER TABLE ... TYPE varchar(N) or use TEXT
  3. Truncate or validate input length at the application layer
  4. Consider whether the value should be stored in a separate detail table

Code Examples

Widen a varchar column sql
ALTER TABLE profiles ALTER COLUMN name TYPE varchar(120);

Increasing the length limit is safe and online; truncating existing data would require a USING clause.

Framework-Specific Fixes

django

Use max_length on CharField; Django validates before sending oversized strings.

class Profile(models.Model):
    name = models.CharField(max_length=50)
sqlalchemy

Set String(length=...) and validate length in Python.

name = Column(String(50))
supabase

Widen the column type in the Table Editor, or validate length before insert.

ALTER TABLE profiles ALTER COLUMN name TYPE varchar(120);

You Might Also Like

Frequently Asked Questions

Why am I seeing PostgreSQL error 22001?

Most often this happens when inserting a value longer than varchar(N) or char(N), or when concatenated/derived strings exceeding the column width.

How do I fix PostgreSQL error 22001?

Check the column's defined length with \d table or information_schema.

Which frameworks have documented fixes for error 22001?

This page documents fixes for: django, sqlalchemy, supabase.

Official Sources

This page is based on the official PostgreSQL documentation linked below and adds practical troubleshooting guidance on top.