01004WARNINGTier 2 — Caution✅ HIGH confidencestring 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
- 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.
INSERT INTO products (sku) VALUES ('TOOLONGVALUE123');Fix 1: Truncate the input explicitly before insert
When the data source can produce oversized strings.
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 the column size was set too small for actual values.
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
Why it's wrong: Silent data loss can corrupt business-critical identifiers and codes.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 01 — Warning
Confidence assessment
✅ HIGH confidence
Standard SQL warning. See also error-class 22001 for the stricter error variant.
See also
🔗 Related errors
📄 Reference pages