Diagnostic Queries
Symptoms
A floating-point computation produced a magnitude too small to represent (underflow). PostgreSQL raises SQLSTATE 22003 (numeric_value_out_of_range).
- A result is smaller than the smallest representable nonzero value.
- Common with division or exponential operations.
- Affects
real/double precisioncomputations.
What the server log shows
ERROR: value out of range: underflow
Why PostgreSQL raises this — what the manual says
Section 8.1.3 Floating-Point Types:
“Numbers too close to zero that are not representable as distinct from zero will cause an underflow error.”
IEEE 754 types have a smallest representable nonzero magnitude. A computation producing a value below that threshold underflows, and PostgreSQL reports 22003.
Common causes
- Repeated division producing extremely small numbers.
- Exponential/logarithmic math driving values toward zero.
- Scaling values below the type’s precision floor.
How to fix it
- Use
numericfor arbitrary precision where tiny magnitudes matter. - Rescale the computation to keep values in range.
- Clamp or round near-zero results in the application.
Related & next steps
Reference: PostgreSQL 18 Section 8.1 “Numeric Types”.
Thanks — noted. This helps keep the database accurate.