scribase
SQLSTATE 22P02invalid_text_representationHTTP 400

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.

Other class 22 errors

  • 22001 value too long for type character varying(n)
  • 22003 integer out of range / numeric field overflow
  • 22007 invalid input syntax for type timestamp / date
  • 22008 date/time field value out of range
  • 22012 division by zero