DBAtlas · Database operations atlas

22P02: invalid_text_representation

PostgreSQL

What does it mean?

A text value was not a valid representation for the target data type during conversion. For example, trying to convert the text 'abc' to integer raises this error.

Why does it happen?

Non-numeric text sent to a numeric column/parameter; an empty string ('') converted to a number/date; invalid text for a UUID or enum; malformed JSON; input data not in the expected format.

How to fix it

Verify that the converted value is actually valid. Validate input in the application before type conversion. Convert empty strings to NULL: NULLIF(value, ''). For safe conversion on PostgreSQL 16+, test the value beforehand with pg_input_is_valid('abc', 'integer') and use pg_input_error_info() for error details; on older versions, consider a validation check (regex). Narrow down which row is bad.

Open in DBAtlas →

More from this engine