Diagnostic Queries
Symptoms
A numeric computation or conversion produced a value larger than the target type can hold. PostgreSQL raises SQLSTATE 22003 (numeric_value_out_of_range).
- Arithmetic result exceeds the type’s maximum.
- Common with multiplication/addition near the type’s limit.
- Also seen casting a large value into a narrower type.
What the server log shows
ERROR: value out of range: overflow
Why PostgreSQL raises this — what the manual says
Section 8.1.3 Floating-Point Types:
“Values that are too large or too small will cause an error.”
Each numeric type has a fixed range. When an operation or cast produces a value beyond that range, it cannot be represented and PostgreSQL reports 22003 rather than silently wrapping.
Common causes
- Arithmetic exceeding the type’s maximum.
- Casting a large value into a smaller type.
- Accumulating sums that overflow an integer type.
How to fix it
- Use a wider type (e.g.
bigintornumeric). - Cast intermediate results to
numericto avoid integer overflow. - Validate input ranges before computation.
Related & next steps
Reference: PostgreSQL 18 Section 8.1 “Numeric Types”.
Thanks — noted. This helps keep the database accurate.