select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 42 · SYNTAX ERROR OR ACCESS RULE VIOLATION

invalid_function_definition

SQLSTATE
42P13
Condition name
invalid_function_definition
Class
Syntax Error or Access Rule Violation
Source macro
ERRCODE_INVALID_FUNCTION_DEFINITION
Evidence
Source path confirmed
Analysis & operational context

English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗

<h1>42P13 — Invalid function definition</h1>

At a glance

42P13 (invalid_function_definition) Function, aggregate, and trigger declarations can fail validation before execution.

Meaning

Function-definition validation uses this condition for incompatible declarations. Selected core paths cover a polymorphic aggregate transition type that cannot be determined (with a caller-generated internal DETAIL), a function return-type mismatch when the final statement is not a compatible SELECT or DML RETURNING, and trigger functions declaring arguments.

Diagnosis

Classify the message before editing the function: aggregate transition-type inference and its dynamic DETAIL, final statement/RETURNING result versus declared return type, or trigger argument declaration. Compare the stored signature and return type with the body and the trigger contract; a non-returning DML statement or utility command is a different final-statement failure from a bad scalar coercion.

Response

Correct the declaration or body that the message identifies. Supply a determinable aggregate transition type, make the final function statement return the declared type, and read trigger arguments through TG_NARGS/TG_ARGV instead of declaring them. Recreate or replace only after checking dependent callers. If an ERROR is raised inside an explicit transaction, ROLLBACK or ROLLBACK TO a pre-error savepoint before issuing another DDL command.

Messages

Representative source messages include: message: cannot determine transition data type; errdetail_internal: %s; message: return type mismatch in function declared to return %s; DETAIL: Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING.; message: trigger functions cannot have declared arguments; HINT: The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.. Placeholders are filled by the actual object, column, or parameter.

Versions

The locked catalogue shows this condition by PostgreSQL 7.4; behavior here is fixed to PostgreSQL 18.6 source. Catalogue presence is a range boundary, not proof that every message or feature began in that release.

Sources

Source messages, line anchors, and evidence limits are recorded in authored evidence.

Source evidence

Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.

42P13 is the invalid_function_definition condition in Class 42.

Method: Read fixed REL_18_6 errcodes.txt and locked facts.

Limits: Identity does not enumerate all source branches or client failures.

src.errcodes.42P13.18.6

Selected core paths cover a polymorphic aggregate transition type that cannot be determined with a caller-generated internal DETAIL, a function return-type mismatch when the final statement is not a compatible SELECT or DML RETURNING, and trigger functions declaring arguments.

Method: Read selected resolved REL_18_6 report groups and message roles.

Limits: Representative confirmed core paths only; not exhaustive historical or extension coverage.

src.call.42P13.59b4e33cdd3e899e2a030829 src.call.42P13.2ffff7c5778d60ac8f47ff67 src.call.42P13.1f3147b83dd1ece95cf5aaf0

Locked catalogue snapshots show this condition by PostgreSQL 7.4; source behavior here is fixed at PostgreSQL 18.6.

Method: Read locked catalogue facts and definition snapshot.

Limits: First observed release is a lower bound, not precise behavioral introduction.

src.errcodes.42P13.18.6

Message templates

ERROR · message.variant-1

Primary

cannot determine transition data type

Detail

%s

Primary

%s

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

ERROR · message.variant-2

Primary

return type mismatch in function declared to return %s

Detail

Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING.

Primary

Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING.

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

ERROR · message.variant-3

Primary

trigger functions cannot have declared arguments

Hint

The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.

Primary

The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.

Placeholders remain dynamic source fields; no concrete runtime value is claimed.

Reproduction & repair cases

No reproduction case is attached to this condition.

Recorded runtime evidence

No runtime observation is attached to this entry.

Definition snapshot: english-manuals:66ebe20b66ba76f980d3649981c… · English manual source