Postgres error 22P02: invalid text representation
invalid input syntax for type uuid / integer
A text value could not be converted to the column or parameter type.
Common causes
- Passing a non-UUID string where a uuid is expected, such as the literal "undefined" or "null" from JavaScript, or an empty string.
- Sending "abc" or "12.5" to an integer column or filter.
- A malformed array or JSON literal.
How to fix it
- Check the value in the app before the query; for ids from URLs, validate the UUID format and answer 404 early.
- Send null rather than the string "null".
- For JSON, send a real JSON body or use to_jsonb on a properly quoted value.
Through a REST API
PostgREST, the REST layer behind supabase-js and Scribase, answers HTTP 400 for this error and returns the SQLSTATE in the code field of the JSON error body. From supabase-js this usually means a filter like .eq('id', someId) ran while someId was undefined. PostgREST answers 400.
Questions
What does Postgres error 22P02 mean?
22P02 is invalid_text_representation in class 22 (Data Exception). A text value could not be converted to the column or parameter type.
How do I fix 22P02?
Check the value in the app before the query; for ids from URLs, validate the UUID format and answer 404 early. Send null rather than the string "null". For JSON, send a real JSON body or use to_jsonb on a properly quoted value.
What HTTP status does a REST API return for 22P02?
PostgREST, the REST layer behind supabase-js, answers 400.