PostgreSQL 17.12Lab-verified · 2026-12-01

PostgreSQL 22003: numeric field overflow

A number is bigger than the column type or the calculation type can hold.

PostgreSQL 17.12
22003: numeric field overflow

Jump to a cause

  1. 01The value has more integer digits than numeric(p,s) allows
  2. 02A value over about 2.1 billion goes into an int column
  3. 03int * int overflows in a calculation
  4. 04Phone numbers cast to int (overflows with a country code)

Lab-verifiedReproduced and fixed on PostgreSQL 17.12 · 2026-12-01 · container image postgres:17

SQLSTATE 22003 means a number does not fit its type. For numeric(p,s) the message is numeric field overflow, with a DETAIL line about the precision. For int it is integer out of range.

The value can come from an INSERT or from a calculation in a SELECT. Below are four causes verified on PostgreSQL 17.

01The value has more integer digits than numeric(p,s) allows

unit_price numeric(5,2) allows 5 digits in total with 2 after the point, so at most 3 digits before it. Inserting 1234.50 fails. DETAIL says the value must round to an absolute value less than 10^3.

Setup
Setuprun as lab_a
CREATE TABLE prices (id int PRIMARY KEY, unit_price numeric(5,2));
OUTPUT
CREATE TABLE
Reproducerun as lab_a
INSERT INTO prices VALUES (1, 1234.50);
✕ ERROR
ERROR:  22003: numeric field overflow
DETAIL:  A field with precision 5, scale 2 must round to an absolute value less than 10^3.
Checkrun as lab_a
SELECT column_name, numeric_precision, numeric_scale FROM information_schema.columns WHERE table_name = 'prices' AND column_name = 'unit_price';
OUTPUT
 column_name | numeric_precision | numeric_scale
-------------+-------------------+---------------
 unit_price  |                 5 |             2
(1 row)
Fixrun as lab_a
ALTER TABLE prices ALTER COLUMN unit_price TYPE numeric(10,2);
OUTPUT
ALTER TABLE

information_schema.columns shows precision 5, scale 2. Widen the column: ALTER TABLE prices ALTER COLUMN unit_price TYPE numeric(10,2). The same INSERT then stores 1234.50.

After the fixrun as lab_a
INSERT INTO prices VALUES (1, 1234.50);
SELECT * FROM prices;
✓ SUCCESS
INSERT 0 1
 id | unit_price
----+------------
  1 |    1234.50
(1 row)

02A value over about 2.1 billion goes into an int column

external_id is int (4 bytes, up to 2147483647). Inserting 3000000000 gives integer out of range. This often happens with IDs that come from an outside system.

Setup
Setuprun as lab_a
CREATE TABLE events (id int PRIMARY KEY, external_id int);
OUTPUT
CREATE TABLE
Reproducerun as lab_a
INSERT INTO events VALUES (1, 3000000000);
✕ ERROR
ERROR:  22003: integer out of range
Fixrun as lab_a
ALTER TABLE events ALTER COLUMN external_id TYPE bigint;
OUTPUT
ALTER TABLE

Change the column to bigint: ALTER TABLE events ALTER COLUMN external_id TYPE bigint. The INSERT of 3000000000 then succeeds.

After the fixrun as lab_a
INSERT INTO events VALUES (1, 3000000000);
SELECT * FROM events;
✓ SUCCESS
INSERT 0 1
 id | external_id
----+-------------
  1 |  3000000000
(1 row)

03int * int overflows in a calculation

qty and unit_price are both int, so qty * unit_price is computed as int. 50000 * 60000 = 3,000,000,000 is too big, and the whole SELECT fails even though each column value is fine.

Setup
Setuprun as lab_a
CREATE TABLE sales (id int PRIMARY KEY, qty int, unit_price int);
INSERT INTO sales VALUES (1, 50000, 60000), (2, 3, 1000);
OUTPUT
CREATE TABLE
INSERT 0 2
Reproducerun as lab_a
SELECT id, qty * unit_price AS amount FROM sales ORDER BY id;
✕ ERROR
ERROR:  22003: integer out of range
Checkrun as lab_a
SELECT pg_typeof(qty), pg_typeof(unit_price) FROM sales LIMIT 1;
OUTPUT
 pg_typeof | pg_typeof
-----------+-----------
 integer   | integer
(1 row)

pg_typeof shows both columns are integer. Cast one side before multiplying: qty::bigint * unit_price. The result is bigint and the query returns 3000000000 and 3000.

After the fixrun as lab_a
SELECT id, qty::bigint * unit_price AS amount FROM sales ORDER BY id;
✓ SUCCESS
 id |   amount
----+------------
  1 | 3000000000
  2 |       3000
(2 rows)

04Phone numbers cast to int (overflows with a country code)

Phone numbers from a staging table (text) were cast with phone::int into an int column. 01012345678 fits in int, but 821098765432, which has a country code, is above about 2.1 billion (2147483647), so 22003 was raised. The message shows the offending value.

If any row overflows, the whole INSERT fails.

Setup
Setuprun as lab_a
CREATE TABLE stg_members (id int, phone text);
INSERT INTO stg_members VALUES (1, '01012345678'), (2, '821098765432');
CREATE TABLE members (id int PRIMARY KEY, phone int);
OUTPUT
CREATE TABLE
INSERT 0 2
CREATE TABLE
Reproducerun as lab_a
INSERT INTO members SELECT id, phone::int FROM stg_members;
✕ ERROR
ERROR:  22003: value "821098765432" is out of range for type integer
Check the causerun as lab_a
SELECT id, phone, phone::bigint > 2147483647 AS over_int_max FROM stg_members ORDER BY id;
OUTPUT
 id |    phone     | over_int_max
----+--------------+--------------
  1 | 01012345678  | f
  2 | 821098765432 | t
(2 rows)

over_int_max is t only for row 2. That value is above the int maximum.

Fixrun as lab_a
ALTER TABLE members ALTER COLUMN phone TYPE text;
OUTPUT
ALTER TABLE

A phone number is a string, not a number you calculate with, so phone was changed to text. Both rows were then inserted, and the leading 0 of 01012345678 was kept.

After the fixrun as lab_a
INSERT INTO members SELECT id, phone FROM stg_members;
SELECT * FROM members ORDER BY id;
✓ SUCCESS
INSERT 0 2
 id |    phone
----+--------------
  1 | 01012345678
  2 | 821098765432
(2 rows)

FAQ

What does numeric field overflow mean in PostgreSQL?

The value has more digits before the decimal point than numeric(p,s) allows (p minus s). Widen the precision or check the value.

How do I fix integer out of range in PostgreSQL?

If the column must hold values over 2147483647, change it to bigint. If it comes from a calculation, cast one operand with ::bigint.

Why does SUM or a multiplication give integer out of range?

An int * int result is also int. In our test qty * unit_price failed and qty::bigint * unit_price worked.

What is the Korean or Japanese message for 22003?

Korean: 수치 필드 오버플로우 / 정수 범위를 벗어남. Japanese: numericフィールドのオーバーフロー / integerの範囲外です.

How do I fix value "..." is out of range for type integer?

The value is outside the int range (about ±2.1 billion). Use bigint for numbers you calculate with, or text for strings such as phone numbers and codes. In the run above a phone number with a country code overflowed, and switching to text fixed it.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary roles created for the test, each owning a schema of the same name; postgres is the superuser. PostgreSQL 17.12