실제 DB 검증PostgreSQL 17.12에서 재현·해결 확인 · 2026-12-01 · 컨테이너 이미지 postgres:17
SQLSTATE 22003은 숫자가 타입에 안 들어간다는 뜻이에요. numeric(p,s)면 '수치 필드 오버플로우'(numeric field overflow)와 자릿수를 알려 주는 DETAIL이, int면 '정수 범위를 벗어남'(integer out of range)이 나와요.
INSERT 값뿐 아니라 SELECT 안 계산에서도 나요. PostgreSQL 17에서 확인한 4가지 원인이에요.
01numeric(p,s)보다 정수부 자릿수가 많음
unit_price numeric(5,2)는 전체 5자리 중 소수 2자리라 정수부는 3자리까지예요. 1234.50을 넣으면 실패하고, DETAIL에 절댓값이 10^3보다 작아야 한다고 나와요.
사전 준비
CREATE TABLE prices (id int PRIMARY KEY, unit_price numeric(5,2));CREATE TABLEINSERT INTO prices VALUES (1, 1234.50);ERROR: 22003: numeric field overflow
DETAIL: A field with precision 5, scale 2 must round to an absolute value less than 10^3.SELECT column_name, numeric_precision, numeric_scale FROM information_schema.columns WHERE table_name = 'prices' AND column_name = 'unit_price'; column_name | numeric_precision | numeric_scale
-------------+-------------------+---------------
unit_price | 5 | 2
(1 row)ALTER TABLE prices ALTER COLUMN unit_price TYPE numeric(10,2);ALTER TABLEinformation_schema.columns에서 precision 5, scale 2를 확인하고 컬럼을 넓히세요: ALTER TABLE prices ALTER COLUMN unit_price TYPE numeric(10,2). 같은 INSERT로 1234.50이 저장돼요.
INSERT INTO prices VALUES (1, 1234.50);
SELECT * FROM prices;INSERT 0 1
id | unit_price
----+------------
1 | 1234.50
(1 row)02int 컬럼에 약 21억 넘는 값을 넣음
external_id가 int(4바이트, 최대 2147483647)예요. 3000000000을 넣으면 정수 범위를 벗어남이 나요. 외부 시스템에서 받은 ID에서 자주 생겨요.
사전 준비
CREATE TABLE events (id int PRIMARY KEY, external_id int);CREATE TABLEINSERT INTO events VALUES (1, 3000000000);ERROR: 22003: integer out of rangeALTER TABLE events ALTER COLUMN external_id TYPE bigint;ALTER TABLE컬럼을 bigint로 바꾸세요: ALTER TABLE events ALTER COLUMN external_id TYPE bigint. 그러면 3000000000 INSERT가 성공해요.
INSERT INTO events VALUES (1, 3000000000);
SELECT * FROM events;INSERT 0 1
id | external_id
----+-------------
1 | 3000000000
(1 row)03int끼리 곱해서 계산 결과가 넘침
qty와 unit_price가 둘 다 int라 qty * unit_price도 int로 계산돼요. 50000 * 60000 = 30억이 넘쳐서, 컬럼 값은 멀쩡해도 SELECT 전체가 실패해요.
사전 준비
CREATE TABLE sales (id int PRIMARY KEY, qty int, unit_price int);
INSERT INTO sales VALUES (1, 50000, 60000), (2, 3, 1000);CREATE TABLE
INSERT 0 2SELECT id, qty * unit_price AS amount FROM sales ORDER BY id;ERROR: 22003: integer out of rangeSELECT pg_typeof(qty), pg_typeof(unit_price) FROM sales LIMIT 1; pg_typeof | pg_typeof
-----------+-----------
integer | integer
(1 row)pg_typeof로 두 컬럼이 integer인 걸 확인하고, 곱하기 전에 한쪽을 바꾸세요: qty::bigint * unit_price. 결과가 bigint가 돼서 3000000000과 3000이 나와요.
SELECT id, qty::bigint * unit_price AS amount FROM sales ORDER BY id; id | amount
----+------------
1 | 3000000000
2 | 3000
(2 rows)04전화번호를 int로 바꿔 넣음 (국가번호 붙은 번호에서 넘침)
스테이징의 전화번호(text)를 phone::int로 바꿔 int 컬럼에 넣었어요. 01012345678은 int 범위 안이라 통과하지만, 국가번호가 붙은 821098765432는 약 21억(2147483647)을 넘어서 22003이 났어요. 메시지에 문제 값이 그대로 나와요.
한 행이라도 넘치면 INSERT 전체가 실패해요.
사전 준비
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);CREATE TABLE
INSERT 0 2
CREATE TABLEINSERT INTO members SELECT id, phone::int FROM stg_members;ERROR: 22003: value "821098765432" is out of range for type integerSELECT id, phone, phone::bigint > 2147483647 AS over_int_max FROM stg_members ORDER BY id; id | phone | over_int_max
----+--------------+--------------
1 | 01012345678 | f
2 | 821098765432 | t
(2 rows)over_int_max가 2번 행만 t예요. 이 값이 int 최대값을 넘어요.
ALTER TABLE members ALTER COLUMN phone TYPE text;ALTER TABLE전화번호는 계산하는 숫자가 아니라 문자열이라 phone을 text로 바꿨어요. 그러면 두 행 모두 들어가고 01012345678의 앞자리 0도 그대로 남아요.
INSERT INTO members SELECT id, phone FROM stg_members;
SELECT * FROM members ORDER BY id;INSERT 0 2
id | phone
----+--------------
1 | 01012345678
2 | 821098765432
(2 rows)자주 묻는 질문
PostgreSQL numeric field overflow 뜻은?
값의 정수부 자릿수가 numeric(p,s)에서 허용하는 자릿수(p - s)보다 많다는 뜻이에요. 자릿수를 늘리거나 값을 확인하세요.
integer out of range 해결 방법은?
2147483647보다 큰 값을 담아야 하면 컬럼을 bigint로 바꾸세요. 계산에서 나면 한쪽에 ::bigint를 붙이세요.
곱셈만 했는데 integer out of range가 나요
int * int 결과도 int예요. 실행해 보니 qty * unit_price는 실패, qty::bigint * unit_price는 성공했어요.
22003 한국어 메시지는?
'수치 필드 오버플로우'(numeric field overflow), '정수 범위를 벗어남'(integer out of range)으로 나와요.
value "..." is out of range for type integer는 어떻게 고쳐요?
값이 int 범위(약 ±21억)를 넘은 거예요. 숫자로 계산할 값이면 bigint로, 전화번호·코드처럼 문자열이면 text로 바꿔요. 위 실행에서는 국가번호가 붙은 전화번호가 넘쳤고, text로 바꿔 해결했어요.
검증 방법
시나리오마다 새 DB 사용자를 만들어 시작해요. 스크립트가 사전 준비 → 에러 재현(에러 코드 일치 확인) → 해결 → 원래 문장 재실행 순서로 실행하고, 화면의 출력은 DB가 실제로 낸 결과를 스크립트가 그대로 저장한 거예요.
lab_a, lab_b는 테스트용 일반 역할(같은 이름의 스키마 소유), postgres는 슈퍼유저예요. PostgreSQL 17.12