PostgreSQL Error 54023: Too Many Arguments
PostgreSQL error code 54023, "too many arguments," occurs when you call a function or procedure and pass more arguments than the function's signature allows. This error belongs to the 54xxx error class, which covers program limit exceeded scenarios. It's a straightforward but surprisingly common mistake, especially when function signatures change over time or when building dynamic SQL.
Top 3 Causes
1. Calling a Function with Extra Arguments
The most common cause is simply passing more arguments than the function accepts.
-- Define a function that takes 2 arguments
CREATE OR REPLACE FUNCTION add_numbers(a INTEGER, b INTEGER)
RETURNS INTEGER AS $$
BEGIN
RETURN a + b;
END;
$$ LANGUAGE plpgsql;
-- ERROR: too many arguments
SELECT add_numbers(1, 2, 3);
-- CORRECT: match the function signature
SELECT add_numbers(1, 2);
-- Check the function signature before calling
SELECT proname, pg_get_function_arguments(oid) AS arguments
FROM pg_proc
WHERE proname = 'add_numbers';
2. Mismatched Placeholders in format()
When using the format() function, the number of %s, %I, or %L placeholders must exactly match the number of additional arguments provided.
-- ERROR: too many arguments for format()
SELECT format('Hello, %s', 'World', 'ExtraArg');
-- CORRECT: one placeholder, one argument
SELECT format('Hello, %s!', 'World');
-- CORRECT: multiple placeholders matched with arguments
SELECT format(
'UPDATE %I SET %I = %L WHERE id = 1',
'employees',
'salary',
5000
);
3. Dynamic Function Calls in PL/pgSQL
Building argument lists dynamically in PL/pgSQL can lead to runtime mismatches that are invisible during development.
-- UNSAFE: argument count may not match at runtime
CREATE OR REPLACE FUNCTION bad_dynamic_call()
RETURNS VOID AS $$
DECLARE
v_args TEXT := '1, 2, 3'; -- 3 args for a 2-arg function
BEGIN
EXECUTE 'SELECT add_numbers(' || v_args || ')';
END;
$$ LANGUAGE plpgsql;
-- SAFE: use USING clause for parameterized execution
CREATE OR REPLACE FUNCTION safe_dynamic_call(p_a INTEGER, p_b INTEGER)
RETURNS INTEGER AS $$
DECLARE
v_result INTEGER;
BEGIN
EXECUTE 'SELECT add_numbers($1, $2)'
INTO v_result
USING p_a, p_b;
RETURN v_result;
END;
$$ LANGUAGE plpgsql;
SELECT safe_dynamic_call(10, 20);
Quick Fix Solutions
-
Verify the function signature using
pg_procbefore calling it. -
Count your placeholders in
format()and match them to argument count. - Prefer USING clauses over string concatenation for dynamic SQL to enforce argument safety.
-- Always verify before calling
SELECT proname, pronargs, pg_get_function_arguments(oid)
FROM pg_proc
WHERE proname = 'your_function_name'
AND pronamespace = 'public'::regnamespace;
Prevention Tips
Regression test function signatures: Add automated tests that call every user-defined function with correct arguments. Integrate these into your CI/CD pipeline so any signature change that breaks existing callers is caught immediately.
Use named parameters: PostgreSQL supports named argument notation, which makes mismatches more obvious and readable.
-- Named parameter call: clearer and safer
SELECT add_numbers(a => 10, b => 20);
-- This will error clearly if you add a non-existent parameter
-- SELECT add_numbers(a => 10, b => 20, c => 30); -- ERROR
Related Errors
- 42883 (undefined_function): Function not found for the given argument types — often seen alongside 54023 when debugging function calls.
- 22023 (invalid_parameter_value): Argument count is correct, but a value itself is invalid.
- 42P13 (invalid_function_definition): Triggered during function creation when the definition itself is malformed.
📖 Want a more detailed guide?
Check out the full in-depth version (Korean) on oraerror.com — includes detailed analysis, additional SQL examples, and prevention tips.
Top comments (0)