PostgreSQL Error 42723: Duplicate Function Fix
In this article
PostgreSQL error 42723 (duplicate_function) means you are trying to create or rename a function to a name and argument signature that already exists in the same schema. The fix is to either drop or replace the existing function, change the new function's name, or change its argument types so the signature is unique. The signature includes the schema, function name, and input argument types (not the return type), so two functions can share a name if their input types differ.
What You'll Need
- Access to a PostgreSQL client (psql, pgAdmin, DBeaver, or your application's migration tool).
- Permission to create, drop, or replace functions in the target schema (typically the owner or a superuser).
- The exact function name and argument types you are trying to create.
- Optional: the
pg_proccatalog and\dfpsql meta-command for inspection.
Step-by-Step
- Confirm the error. The message usually reads
ERROR: function "name" already exists with same argument typesand SQLSTATE42723. Note the function name and the argument types PostgreSQL lists in the error; those are the conflicting signature. - List existing functions with that name. In psql run
\df schema_name.function_nameor query the catalog:SELECT n.nspname, p.proname, pg_get_function_identity_arguments(p.oid) FROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace WHERE p.proname = 'your_function';. This shows every overload and its exact argument types. - Decide the intent. If you are updating an existing function, use
CREATE OR REPLACE FUNCTIONinstead of plainCREATE FUNCTION. If you are adding a new overload, change the argument types so the signature differs. If the old function is obsolete, drop it first. - Use CREATE OR REPLACE where appropriate.
CREATE OR REPLACE FUNCTION schema.name(arg_types) RETURNS ... AS $$ ... $$ LANGUAGE ...;replaces the body and most attributes. It cannot change the return type or the argument types; doing so raises 42723 or a related error. If you need a different return type, drop and recreate. - Drop the conflicting function if you are replacing its signature. Run
DROP FUNCTION schema.name(arg_types);using the exact argument types from step 2. If other objects depend on it, PostgreSQL blocks the drop; useDROP FUNCTION ... CASCADE;only after checking what will be removed, because CASCADE drops dependent objects. - Recreate with the new signature. After dropping, run your
CREATE FUNCTIONstatement. Verify with\df schema.namethat only the intended version exists. - Update callers. If you changed argument types or dropped an overload, search your codebase and database for calls to the old signature. PostgreSQL resolves overloads by argument types, so a call with mismatched types may fail or silently pick a different overload.
- Wrap migrations idempotently. In migration scripts, guard with
DROP FUNCTION IF EXISTS schema.name(arg_types);before creating, or useCREATE OR REPLACEwhen the signature is unchanged. This prevents 42723 on re-runs.
Common Mistakes
- Assuming the return type is part of the signature. It is not; only input argument types matter for uniqueness.
- Using
CREATE OR REPLACEto change argument types or the return type. That raises an error; drop and recreate instead. - Forgetting the schema. Two functions with the same name and arguments can exist in different schemas; the error refers to the schema in your search_path or the one you qualified.
- Dropping without specifying argument types.
DROP FUNCTION name;fails when overloads exist; always include the argument list. - Using
CASCADEcasually. It can drop views, triggers, or other functions that depend on the function. - Ignoring default arguments. A function with defaults can conflict with an overload that matches the call without those defaults; check the full signature.
Tips
- Use
pg_get_function_identity_arguments(oid)to get the exact argument list for DROP or ALTER statements. - Prefer
CREATE OR REPLACEfor body-only changes; it preserves grants and dependencies. - Keep function signatures stable across migrations to avoid breaking callers.
- Test migrations in a staging database with the same schema and extensions before production.
- Remember that labels and catalog views can differ slightly by PostgreSQL version; check your version's documentation for exact syntax.
Troubleshooting
If the error persists after dropping, confirm you dropped the function in the correct schema and with the exact argument types. Query pg_proc again to verify no row remains. If a drop is blocked by dependencies, inspect them with \df+ or query pg_depend; decide whether to update dependents or use CASCADE. If CREATE OR REPLACE fails because you changed the return type, drop the function and recreate it, then re-grant privileges. If your migration tool reports 42723 on re-run, make the migration idempotent with DROP FUNCTION IF EXISTS or a conditional block. If calls fail after the change, check for overload ambiguity and qualify calls with explicit casts.
Frequently Asked Questions
What causes PostgreSQL error 42723?
It occurs when a CREATE FUNCTION or ALTER FUNCTION ... RENAME targets a name and input argument type list that already exists in the same schema.
Does the return type affect duplicate function errors?
No. Uniqueness is based on schema, function name, and input argument types. Return type is not part of the signature.
Can I use CREATE OR REPLACE to change argument types?
No. CREATE OR REPLACE cannot change the argument types or return type; you must drop and recreate the function.
How do I find the exact argument types of an existing function?
Use \df schema.name in psql or query pg_get_function_identity_arguments(oid) from pg_proc.
Why does DROP FUNCTION fail without argument types?
If multiple overloads exist, PostgreSQL cannot determine which one to drop; include the argument type list.
Is it safe to use DROP FUNCTION ... CASCADE?
Only if you have reviewed dependent objects. CASCADE drops objects that depend on the function, which can include views and triggers.