PostgreSQL raises invalid_function_definition (SQLSTATE 42P13) when a CREATE FUNCTION or CREATE PROCEDURE statement contains an illegal attribute mix, duplicate clause, or a body that conflicts with the declared signature.
PostgreSQL Error 42P13 - invalid_function_definition occurs when the CREATE FUNCTION statement includes conflicting attributes or a body that mismatches the declared signature. Recheck LANGUAGE, RETURNS, parameter types, and remove duplicate clauses to resolve the error.
PostgreSQL Error 42P13
PostgreSQL throws error 42P13 - invalid_function_definition - while parsing a CREATE FUNCTION or CREATE PROCEDURE command that contains incompatible or duplicate clauses, or when the function body contradicts the declared argument and return types.
The server halts execution of the statement to protect catalog integrity.
Developers must fix the definition before the object can be created or replaced.
Conflicting attributes such as specifying both STRICT and CALLED ON NULL INPUT trigger 42P13 immediately.
PostgreSQL treats these flags as mutually exclusive.
Duplicate clauses like two LANGUAGE declarations or two RETURNS clauses violate grammar rules and surface the same error.
A body that does not return the declared data type (for example, returning TEXT when RETURNS integer is declared) also leads to invalid_function_definition at creation time in PL languages that check source code.
Validate each attribute combination and keep only one of each clause.
Ensure the RETURNS clause matches the actual return expression in the body.
Run the function in a test block or use CREATE OR REPLACE with RAISE NOTICE statements to confirm types align.
PL/pgSQL functions that declare RETURNS void but use RETURN query produce 42P13. Change RETURNS to TABLE or SETOF type, or remove the RETURN statement.
Functions copied from another database often include OUT parameters and a RETURNS clause.
Remove RETURNS when OUT parameters already define the result composite type.
Always write the signature first, then stub the body with RETURN NULL to let the parser evaluate clauses before adding logic.
Use Galaxy's linting inside the SQL editor to surface mixed attributes and type mismatches as you type, preventing invalid definitions from reaching the database.
Error 42723 - duplicate_function appears when the name and argument types already exist.
Alter the signature or drop the old function.
Error 42601 - syntax_error may be thrown if the function body has unmatched BEGIN/END or missing semicolons.
.
42P13 exists in all supported versions. Newer releases may introduce extra attribute checks, so review release notes when upgrading.
No. The function is not created until the definition is valid. Fix conflicts first.
Galaxy's real time parser flags duplicate clauses and type mismatches while you type, preventing 42P13 from reaching production.
Use STRICT when null inputs should short circuit execution. Use CALLED ON NULL INPUT when nulls need special handling inside the body.