Common SQL Errors

PostgreSQL numeric_value_out_of_range (22003) Error Explained

August 4, 2025

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.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is numeric_value_out_of_range in PostgreSQL?

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.

Error Highlights

Typical Error Message

numeric_value_out_of_range

Error Type

Data Error

Language

PostgreSQL

Symbol

numeric_value_out_of_range

Error Code

22003

SQL State

Explanation

Table of Contents

What is numeric_value_out_of_range in PostgreSQL?

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.

What Causes This Error?

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.

How to Fix numeric_value_out_of_range

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.

Common Scenarios and Solutions

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).

Best Practices to Avoid This Error

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.

Related Errors and Solutions

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.

.

Common Causes

Related Errors

FAQs

Why did my SUM() query suddenly fail?

Total aggregation can exceed BIGINT even if individual rows fit. Cast to NUMERIC inside SUM.

Can I disable the check temporarily?

No. PostgreSQL enforces type safety. You must widen the type or clamp data.

Does increasing scale fix the error?

Scale controls decimals, not total digits. Increase overall precision instead.

How does Galaxy help?

Galaxy’s AI copilot inspects column stats and suggests safer data types before you run migrations, preventing production errors.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo