PostgreSQLERROR 22001

PostgreSQL: Value Too Long for Type Character Varying

PostgreSQL 22001 is raised when a string value exceeds the maximum length declared for a VARCHAR(n) column. Unlike MySQL in non-strict mode, PostgreSQL never silently truncates.

Example Query

CREATE TABLE users (username VARCHAR(20));
INSERT INTO users (username) VALUES ('this_username_is_too_long_for_the_column');

Common Causes

  1. 1Application data grew beyond what the schema anticipated
  2. 2Column size too small for internationalised content
  3. 3Import from a system with a larger column definition

How to Fix It

Increase the column size: ALTER TABLE users ALTER COLUMN username TYPE VARCHAR(100). Consider using TEXT for variable-length fields where you do not need a hard limit. Validate lengths in the application before inserting.

Need a reliable database?

Try Supabase — free PostgreSQL with a generous free tier. No credit card required.

Get started free →

Got a query causing this error?

Paste it into SQLbuddy and get an instant plain-English explanation with optimization tips.

Analyze My Query →