numeric_value_out_of_range (SQLSTATE 22003) appears when an arithmetic result, literal, or inserted value is outside the range that the target data type can store.
numeric_value_out_of_range happens when a value exceeds the allowed range for its PostgreSQL data type. Fix it by choosing a larger type (for example, change SMALLINT to INTEGER) or scaling the data before the insert or calculation.
numeric_value_out_of_range
PostgreSQL raises numeric_value_out_of_range (error code 22003) when the engine cannot fit a number into the destination data type. The failure can occur during INSERT, UPDATE, arithmetic operations, or casts.
The error stops the statement, rolls back the current transaction block if needed, and must be fixed before data can be written.
Because it signals potential data loss, correcting it quickly is essential for data integrity.
The error surfaces when a literal or computed value exceeds the upper or lower bound of the column or variable type.
Each numeric type has a finite range: SMALLINT (-32768..32767), INTEGER (-2147483648..2147483647), BIGINT (-9223372036854775808..9223372036854775807), and NUMERIC/DECIMAL with user-defined precision and scale.
Arithmetic expressions that overflow, such as multiplying two BIGINT values whose product is outside BIGINT’s range, also trigger the exception.
First, confirm which column or expression overflows by enabling client_min_messages = debug or examining the full error detail.
Then pick one of three remedies: choose a wider data type, tighten the data so it fits, or cast/round values on write.
Changing the column type to INTEGER or NUMERIC with higher precision is the most common and future-proof solution.
Overflow during INSERT – inserting 40000 into a SMALLINT column. Fix by altering the column to INTEGER.
Overflow during aggregation – SUM() on BIGINT salaries pushes the result past BIGINT.
Cast the column to NUMERIC inside SUM or use SUM(salary::numeric).
Model columns with realistic growth in mind, prefer NUMERIC for monetary amounts, and add CHECK constraints to validate ranges. Test edge cases in staging.
Use Galaxy’s inline result previews and AI copilot to profile column maxima quickly, helping you spot potential overflows before deploying.
division_by_zero (22012) arises in similar arithmetic contexts; fix by guarding denominators.
arithmetic_exception is a parent class encompassing both errors. out_of_memory can appear when casting extremely large NUMERIC values; reduce precision or batch inserts.
.
Total aggregation can exceed BIGINT even if individual rows fit. Cast to NUMERIC inside SUM.
No. PostgreSQL enforces type safety. You must widen the type or clamp data.
Scale controls decimals, not total digits. Increase overall precision instead.
Galaxy’s AI copilot inspects column stats and suggests safer data types before you run migrations, preventing production errors.