SQLSTATE 22003numeric_value_out_of_rangeHTTP 400
Postgres error 22003: numeric value out of range
integer out of range / numeric field overflow
A number does not fit the column or expression type.
Common causes
- A value above 2147483647 in an integer column, often an id or a counter that outgrew int4.
- Arithmetic on two integers that overflows before it is cast to a bigger type.
- A numeric(p, s) column whose precision is too small for the value.
How to fix it
- Move ids and counters to bigint (alter column ... type bigint; this rewrites the table, so plan it for a quiet time on big tables).
- Cast before multiplying: a::bigint * b.
- Widen numeric precision.
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.
Questions
What does Postgres error 22003 mean?
22003 is numeric_value_out_of_range in class 22 (Data Exception). A number does not fit the column or expression type.
How do I fix 22003?
Move ids and counters to bigint (alter column ... type bigint; this rewrites the table, so plan it for a quiet time on big tables). Cast before multiplying: a::bigint * b. Widen numeric precision.
What HTTP status does a REST API return for 22003?
PostgREST, the REST layer behind supabase-js, answers 400.