01004
PostgreSQLWARNINGNotableWarningHIGH confidence

string data right truncation

What this means

SQLSTATE 01004 (warning class) is raised when a string value is silently truncated to fit the declared length of a VARCHAR(n) or CHAR(n) column. This is a warning-level notification; in some contexts Postgres raises the error-level 22001 instead.

Why it happens
  1. 1Inserting or updating a character column with a string longer than the column declaration allows
How to reproduce

Inserting an oversized string into a VARCHAR(10) column in a context where truncation is permitted.

trigger — this will error
trigger — this will error
INSERT INTO products (sku) VALUES ('TOOLONGVALUE123');

expected output

WARNING:  string data right truncation

Fix 1

Truncate the input explicitly before insert

WHEN When the data source can produce oversized strings.

Truncate the input explicitly before insert
INSERT INTO products (sku) VALUES (LEFT('TOOLONGVALUE123', 10));

Why this works

LEFT() enforces the length limit in SQL before the row is written, documenting intent clearly.

Fix 2

Widen the column if the data legitimately needs more space

WHEN When the column size was set too small for actual values.

Widen the column if the data legitimately needs more space
ALTER TABLE products ALTER COLUMN sku TYPE VARCHAR(30);

Why this works

Resizing the column prevents truncation without data loss.

What not to do

Rely on silent truncation in production

Silent data loss can corrupt business-critical identifiers and codes.

Sources
Official documentation ↗

Class 01 — Warning

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors