Skip to content
PostgreSQL

PostgreSQL Error 22003

integer out of range

Applies to: PostgreSQL 13 to 18 (examples run on PostgreSQL 18.6 in PGlite)
Last technically reviewed 24 October 2026 on PostgreSQL 18.6 (PGlite 0.5.11)
The full message
ERROR:  integer out of range
Other forms of this message
smallint (and bigint) columns or arithmetic
ERROR:  smallint out of range
numeric(p, s) value with too many digits before the decimal point
ERROR:  numeric field overflow
DETAIL:  A field with precision 5, scale 2 must round to an absolute value less than 10^3.
A quoted value that is too large for the type
ERROR:  value "3000000000" is out of range for type integer
double precision arithmetic
ERROR:  value out of range: overflow
numeric arithmetic beyond the numeric format
ERROR:  value overflows numeric format
SQLSTATE
22003
Condition name
numeric_value_out_of_range
Product
PostgreSQL
Versions
PostgreSQL 13 to 18 (examples run on PostgreSQL 18.6 in PGlite)
Last reviewed
24 October 2026

What it means

SQLSTATE 22003 means a number is too large (or too small) for its data type, either when it is stored in a column or while an expression is being calculated.

Each numeric type has a fixed range: smallint holds -32768 to 32767, integer -2147483648 to 2147483647, bigint about plus or minus 9.2 quintillion. A numeric(p, s) column holds at most p digits, s of them after the decimal point, so numeric(5,2) can store up to 999.99. When a value falls outside the range of its type, PostgreSQL raises 22003 (numeric_value_out_of_range) instead of wrapping round or truncating.

The error is just as common in calculations as in stored data. The result of an operation has the type of its inputs, so multiplying two integer columns is done in integer and fails as soon as the product passes 2147483647, even if you only want to display it. The bare message integer out of range does not name the column; check every integer column and expression in the statement. A serial or identity sequence that reaches its maximum raises a different error, nextval: reached maximum value of sequence (SQLSTATE 2200H), but the remedy, moving to bigint, is the same.

Common causes

  • An integer expression overflows: counts, cents or milliseconds multiplied together in integer arithmetic.
  • A value larger than 2147483647 is stored in an integer column, often an external id, a phone number or a file size in bytes.
  • A numeric(p, s) column was sized too small for the values it now has to hold, such as prices above 999.99 in numeric(5,2).
  • A smallint column is used for quantities or stock that later exceed 32767.
  • A floating point calculation such as power() or exp() overflows double precision.

Diagnose it

Read-only These queries only read the system catalogs (pg_catalog, information_schema) and statistics views such as pg_stat_activity and pg_locks. They do not change data, roles or settings, so they are safe to run first.

Which columns and types are involved?

SELECT column_name, data_type, numeric_precision, numeric_scale
FROM information_schema.columns
WHERE table_name = 'orders'
  AND data_type IN ('smallint', 'integer', 'bigint', 'numeric', 'real', 'double precision')
ORDER BY ordinal_position;
What to look for

Each numeric column with its type, and for numeric the precision and scale. Compare these with the values in the failing statement; the message does not say which column overflowed.

How close are the existing values to the limit?

SELECT max(views) AS highest_views,
       2147483647 - max(views) AS headroom
FROM page_stats;
What to look for

The largest stored value and how much room is left before integer overflows. A small headroom means inserts or updates will start to fail soon.

Are any sequences close to their maximum?

SELECT schemaname, sequencename, data_type, last_value, max_value,
       round(100.0 * last_value / max_value, 2) AS pct_used
FROM pg_sequences
ORDER BY pct_used DESC NULLS LAST;
What to look for

Every sequence with the share of its range already used. An integer-typed sequence high on this list needs moving to bigint before it runs out.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Do the arithmetic in bigint or numeric

Read-only

Cast one operand before the operation so the whole expression uses the wider type. Casting the result afterwards is too late: the overflow has already happened.

SELECT page_id, views::bigint * 1000 AS views_x1000
FROM page_stats;

Widen the column to bigint

Changes schema

For ids and counters that outgrow integer, change the column (and every column that references it) to bigint. For a serial or identity column, also change the sequence with ALTER SEQUENCE ... AS bigint so its maximum rises.

Caution: Changing integer to bigint rewrites the whole table and its indexes under an ACCESS EXCLUSIVE lock, blocking reads and writes for the duration. On large tables plan a maintenance window or an online migration (new column, backfill in batches, swap), and change referencing foreign key columns too.

ALTER TABLE page_stats
    ALTER COLUMN views TYPE bigint;

Increase the precision of a numeric column

Changes schema

Choose a precision that fits the largest realistic value, for example numeric(12,2) for money amounts. Keep the scale if the number of decimal places is fixed.

Caution: This takes an ACCESS EXCLUSIVE lock on the table. Check the ALTER TABLE documentation for when a rewrite is avoided, and test on a copy of a large table first.

ALTER TABLE orders
    ALTER COLUMN total TYPE numeric(12,2);

Examples

Integer multiplication that overflows

3000000 fits in integer, but the product 3000000000 does not. views::bigint * 1000 returns 3000000000.

CREATE TABLE page_stats (page_id int, views int);
INSERT INTO page_stats VALUES (1, 3000000);

SELECT page_id, views * 1000 AS views_x1000 FROM page_stats;
Result
ERROR:  integer out of range

Reproduced on PGlite 0.5.11 (PostgreSQL 18.6 compiled to WebAssembly), 24 October 2026.

A price too large for numeric(5,2)

CREATE TABLE orders (id int PRIMARY KEY, total numeric(5,2));

INSERT INTO orders VALUES (1, 1234.50);
Result
ERROR:  numeric field overflow
DETAIL:  A field with precision 5, scale 2 must round to an absolute value less than 10^3.

Reproduced on PGlite 0.5.11 (PostgreSQL 18.6 compiled to WebAssembly), 24 October 2026.

Stock above the smallint range

CREATE TABLE products (id int PRIMARY KEY, stock smallint);

INSERT INTO products VALUES (1, 40000);
Result
ERROR:  smallint out of range

Reproduced on PGlite 0.5.11 (PostgreSQL 18.6 compiled to WebAssembly), 24 October 2026.

How to prevent it

Use bigint (or bigint GENERATED ALWAYS AS IDENTITY) for surrogate keys and counters that can grow without limit, and do not store external identifiers, phone numbers or byte sizes in integer. Size numeric columns for the largest value the business can produce, not today's.

Watch pg_sequences and the maximum of key columns, and plan type changes long before the limit. In calculations, cast to bigint or numeric before multiplying or summing large values.

Common questions

How do I fix "integer out of range" in PostgreSQL?

Find the value or expression that overflows. In a calculation, cast one operand to bigint before the operation (views::bigint * 1000). For stored values, change the column to bigint, which rewrites the table, so plan it.

What does "numeric field overflow" mean?

The value has more digits before the decimal point than numeric(p, s) allows. The DETAIL line gives the limit: precision 5, scale 2 must round to less than 10^3, so the largest value is 999.99. Increase the precision or check the input.

My serial id stopped at 2147483647. Is that this error?

Not exactly: when an integer sequence runs out, nextval raises "reached maximum value of sequence" with SQLSTATE 2200H. The fix is the same idea: change the id column, referencing columns and the sequence to bigint.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 24 October 2026; examples and diagnostics run on PostgreSQL 18.6 (PGlite 0.5.11). SQL-level examples were run in PGlite (PostgreSQL compiled to WebAssembly); examples that need a running server are shown as documented in the PostgreSQL documentation.

Still stuck on a PostgreSQL error?

Browse the full PostgreSQL error library, or get hands-on help from an experienced SQL professional.