Diagnostic Queries
Symptoms
A CREATE FUNCTION tried to create a function whose name and argument types match an existing one. PostgreSQL raises SQLSTATE 42723 (duplicate_function).
- A function with that signature already exists.
- Functions are identified by name plus argument types.
- Common when forgetting OR REPLACE.
What the server log shows
ERROR: function get_total(integer) already exists with same argument types
Why PostgreSQL raises this — what the manual says
the CREATE FUNCTION reference (Description):
“CREATE OR REPLACE FUNCTION will either create a new function, or replace an existing definition.”
PostgreSQL identifies functions by name and input argument types (overloading). Creating one with an identical signature collides with the existing function, so it reports 42723.
Common causes
- Creating a function without
OR REPLACEwhen it already exists. - Re-running a migration.
- An identical signature to an existing overload.
How to fix it
- Use
CREATE OR REPLACE FUNCTIONto update the body. - Change the argument types if you intend a new overload.
- Drop the existing function first if you must change its return type.
Related & next steps
Reference: PostgreSQL 18 — CREATE FUNCTION.
Thanks — noted. This helps keep the database accurate.