This error occurs when you attempt to insert or update a string value that exceeds the maximum length defined by a VARCHAR(n) or CHAR(n) column. PostgreSQL enforces strict length constraints that prevent oversized strings from being stored.
PostgreSQL raises this error (SQLSTATE 22026) when the actual length of a string exceeds the maximum length constraint defined for the column. This typically happens with VARCHAR(n) and CHAR(n) data types, where n represents the maximum number of characters allowed. Unlike some databases that silently truncate oversized strings, PostgreSQL enforces this constraint strictly to maintain data integrity. The error message indicates a schema validation failure—the application or query is trying to store data that violates the column's length constraint. This can originate from web forms, bulk data imports (CSV/ETL), programmatic inserts, or schema mismatches between your application and database.
Review your PostgreSQL error logs to find the exact query and column name:
-- Enable detailed error messages
SET client_min_messages = DETAIL;
-- Re-run the failing query to see column details
INSERT INTO users (name) VALUES ('very long name...');The error message will include the column name and its constraint.
Query the information schema to see the current column constraints:
SELECT column_name, character_maximum_length, data_type
FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'name';This shows the actual VARCHAR(n) or CHAR(n) limit.
You can also use \d table_name in psql for a quick view.
The most common solution is to increase the column's maximum length:
ALTER TABLE users ALTER COLUMN name TYPE VARCHAR(500);In PostgreSQL 12+, changing VARCHAR length upward is a metadata-only operation and completes instantly without rewriting the table. Choose a length that accommodates your data with some buffer.
If you're importing data from CSV or an external source, use a staging table with looser constraints:
-- Create a staging table with TEXT (no length limit)
CREATE TABLE users_staging AS
SELECT * FROM users WHERE FALSE;
ALTER TABLE users_staging ALTER COLUMN name TYPE TEXT;
-- Import data into staging table
COPY users_staging FROM stdin;
-- Clean and validate before moving to production
INSERT INTO users (name)
SELECT SUBSTRING(name, 1, 500) FROM users_staging
WHERE LENGTH(name) <= 500;If you don't have strict length requirements, use TEXT instead of VARCHAR(n):
ALTER TABLE users ALTER COLUMN name TYPE TEXT;TEXT accepts strings of any length up to 1 GB and performs identically to VARCHAR. If you need to enforce a maximum for business reasons, use a CHECK constraint instead:
ALTER TABLE users
ADD CONSTRAINT name_length_check CHECK (LENGTH(name) <= 500);Prevent the error from happening by validating string length in your application before sending to PostgreSQL:
// Node.js / JavaScript example
const MAX_NAME_LENGTH = 500;
if (userData.name && userData.name.length > MAX_NAME_LENGTH) {
throw new Error(`Name must be ${MAX_NAME_LENGTH} characters or less`);
}
await prisma.user.create({ data: userData });This provides better user feedback and reduces unnecessary database round-trips.
PostgreSQL's strict string length enforcement differs from some other databases that silently truncate oversized strings. This is intentional—it follows the SQL standard and catches data integrity issues early.
For migration scenarios where you're copying data between columns with different lengths, use SUBSTRING() or LEFT() to truncate before insertion:
INSERT INTO new_table (short_name)
SELECT SUBSTRING(old_table.long_name, 1, 50) FROM old_table;If you're using an ORM like Prisma or SQLAlchemy, ensure your schema validation (Zod, Yup, Pydantic, etc.) matches your database column definitions to catch mismatches early in the application layer.
ERROR: syntax error at end of input
Syntax error at end of input in PostgreSQL
Bind message supplies N parameters but prepared statement requires M
Bind message supplies N parameters but prepared statement requires M in PostgreSQL
Multidimensional arrays must have sub-arrays with matching dimensions
Multidimensional arrays must have sub-arrays with matching dimensions
ERROR: value too long for type character varying
Value too long for type character varying
insufficient columns in unique constraint for partition key
How to fix "insufficient columns in unique constraint for partition key" in PostgreSQL