실제 DB 검증PostgreSQL 17.12에서 재현·해결 확인 · 2026-11-29 · 컨테이너 이미지 postgres:17
PostgreSQL은 이름이 같고 인수 타입이 다른 함수(오버로드)를 허용해요. 호출이 둘 이상에 똑같이 맞으면 42725 function ... is not unique와 Could not choose a best candidate function. You might need to add explicit type casts. 힌트를 내요. 이름만으로 DROP FUNCTION 하면 function name "..." is not unique가 나요.
아래 3가지는 실무에서 이렇게 되는 대표적인 경우예요. 매번 먼저 SELECT oid::regprocedure FROM pg_proc WHERE proname = '...'로 있는 함수 시그니처를 확인했어요.
01DEFAULT 인수가 있는 새 함수가 기존 함수와 겹침
order_tax(int)가 있는데 order_tax(int, rate int DEFAULT 10)를 추가했어요. SELECT order_tax(1000)은 둘 다에 맞아서 function order_tax(integer) is not unique로 실패했어요.
pg_proc에 order_tax(integer)와 order_tax(integer,integer)가 있었어요. DROP FUNCTION order_tax(int)로 옛 함수를 지우니 기본값 버전만 남아 order_tax(1000)이 100을 돌려줬어요.
사전 준비
CREATE FUNCTION order_tax(amount int) RETURNS int LANGUAGE sql AS $$ SELECT amount / 10 $$;
CREATE FUNCTION order_tax(amount int, rate int DEFAULT 10) RETURNS int LANGUAGE sql AS $$ SELECT amount * rate / 100 $$;CREATE FUNCTION
CREATE FUNCTIONSELECT order_tax(1000);ERROR: 42725: function order_tax(integer) is not unique
LINE 1: SELECT order_tax(1000);
^
HINT: Could not choose a best candidate function. You might need to add explicit type casts.SELECT oid::regprocedure AS signature FROM pg_proc WHERE proname = 'order_tax'; signature
----------------------------
order_tax(integer)
order_tax(integer,integer)
(2 rows)DROP FUNCTION order_tax(int);DROP FUNCTIONCREATE OR REPLACE로 인수를 하나 추가했을 때 흔해요. 인수 목록이 다르면 바꾸기가 아니라 새 함수가 생겨요.
SELECT order_tax(1000); order_tax
-----------
100
(1 row)02bigint용·numeric용 함수가 있는데 정수 리터럴로 호출
fmt_amount(bigint)와 fmt_amount(numeric)이 있었어요. 리터럴 100은 integer라 둘 다로 바꿀 수 있어서 SELECT fmt_amount(100)이 42725로 실패했어요.
인수를 형 변환하니 하나로 정해졌어요. fmt_amount(100::bigint)는 bigint 100, fmt_amount(100::numeric)은 numeric 100을 돌려줬어요.
사전 준비
CREATE FUNCTION fmt_amount(v bigint) RETURNS text LANGUAGE sql AS $$ SELECT 'bigint ' || v $$;
CREATE FUNCTION fmt_amount(v numeric) RETURNS text LANGUAGE sql AS $$ SELECT 'numeric ' || v $$;CREATE FUNCTION
CREATE FUNCTIONSELECT fmt_amount(100);ERROR: 42725: function fmt_amount(integer) is not unique
LINE 1: SELECT fmt_amount(100);
^
HINT: Could not choose a best candidate function. You might need to add explicit type casts.SELECT oid::regprocedure AS signature FROM pg_proc WHERE proname = 'fmt_amount'; signature
---------------------
fmt_amount(bigint)
fmt_amount(numeric)
(2 rows)SELECT fmt_amount(100::bigint) AS a, fmt_amount(100::numeric) AS b; a | b
------------+-------------
bigint 100 | numeric 100
(1 row)03오버로드가 있는데 이름만으로 DROP FUNCTION
get_price(int)와 get_price(text)가 있었어요. DROP FUNCTION get_price;가 function name "get_price" is not unique와 Specify the argument list to select the function unambiguously. 힌트로 실패했어요.
DROP FUNCTION get_price(text)로 인수 타입을 쓰니 그것만 지워지고 pg_proc에는 get_price(integer)만 남았어요.
사전 준비
CREATE FUNCTION get_price(id int) RETURNS int LANGUAGE sql AS $$ SELECT 100 $$;
CREATE FUNCTION get_price(code text) RETURNS int LANGUAGE sql AS $$ SELECT 200 $$;CREATE FUNCTION
CREATE FUNCTIONDROP FUNCTION get_price;ERROR: 42725: function name "get_price" is not unique
HINT: Specify the argument list to select the function unambiguously.SELECT oid::regprocedure AS signature FROM pg_proc WHERE proname = 'get_price'; signature
--------------------
get_price(integer)
get_price(text)
(2 rows)DROP FUNCTION get_price(text);
SELECT oid::regprocedure AS signature FROM pg_proc WHERE proname = 'get_price';DROP FUNCTION
signature
--------------------
get_price(integer)
(1 row)자주 묻는 질문
같은 이름 함수가 몇 개인지 어떻게 봐요?
SELECT oid::regprocedure FROM pg_proc WHERE proname = '함수명';을 실행해요. 한 줄이 인수 타입이 붙은 함수 하나예요.
CREATE OR REPLACE 했는데 왜 함수가 두 개가 됐어요?
CREATE OR REPLACE는 인수 타입이 같을 때만 바꿔요. 인수 목록이 다르면 오버로드가 하나 더 생겨요.
함수를 안 지우고 해결하려면요?
하나에만 맞도록 인수를 형 변환해요. 예: fmt_amount(100::numeric).
DROP FUNCTION에서 function name is not unique는요?
그 이름의 함수가 여러 개라는 뜻이에요. DROP FUNCTION get_price(text);처럼 인수 타입을 써요.
검증 방법
시나리오마다 새 DB 사용자를 만들어 시작해요. 스크립트가 사전 준비 → 에러 재현(에러 코드 일치 확인) → 해결 → 원래 문장 재실행 순서로 실행하고, 화면의 출력은 DB가 실제로 낸 결과를 스크립트가 그대로 저장한 거예요.
lab_a, lab_b는 테스트용 일반 역할(같은 이름의 스키마 소유), postgres는 슈퍼유저예요. PostgreSQL 17.12