DBAtlas · Database operations atlas

22001: string_data_right_truncation

PostgreSQL

What does it mean?

The value would have been truncated because the text length exceeds the defined length of the target column (e.g. VARCHAR(n)); PostgreSQL rejects it and raises an error.

Why does it happen?

Inserting or updating text longer than n into a VARCHAR(n)/CHAR(n) column, longer-than-expected data coming from the application, or a column length defined too narrowly for the need.

How to fix it

Shorten the value so that it fits the column, or increase the column length: ALTER TABLE my_table ALTER COLUMN my_column TYPE VARCHAR(500). If unlimited text is needed, use the TEXT type. Validate length in the application. If you want deliberate truncation, apply LEFT(value, n) explicitly.

Open in DBAtlas →

More from this engine