42P13 — Invalid function definition
42P13 (invalid_function_definition) Function, aggregate, and trigger declarations can fail validation before execution.
English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- aliases
- Unknown
- class name
- Syntax Error or Access Rule Violation
- condition name
- invalid_function_definition
- lang
- en
- sqlstate
- 42P13
Definition PG 18
42P13 — Invalid function definition
At a glance {#at-a-glance}
42P13 (invalid_function_definition) Function, aggregate, and trigger declarations can fail validation before execution.
Meaning {#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 {#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 {#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 {#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 {#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.
Related {#related}
Sources {#sources}
Source messages, line anchors, and evidence limits are recorded in authored evidence.
src/backend/catalog/pg_aggregate.c:142-145(fixed source)src/backend/executor/functions.c:2222-2226(fixed source)src/pl/plpgsql/src/pl_comp.c:493-496(fixed source)
Compare versions
SQLSTATE evidence and recorded runtime versions
claims · identity.class-and-condition
{
"claim_id": "identity.class-and-condition",
"limits": "Identity does not enumerate all source branches or client failures.",
"method": "Read fixed REL_18_6 errcodes.txt and locked facts.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.42P13.18.6"
],
"statement": "42P13 is the invalid_function_definition condition in Class 42."
}claims · mechanism.selected-source-path
{
"claim_id": "mechanism.selected-source-path",
"limits": "Representative confirmed core paths only; not exhaustive historical or extension coverage.",
"method": "Read selected resolved REL_18_6 report groups and message roles.",
"position": 1,
"runtime": [],
"sources": [
"src.call.42P13.59b4e33cdd3e899e2a030829",
"src.call.42P13.2ffff7c5778d60ac8f47ff67",
"src.call.42P13.1f3147b83dd1ece95cf5aaf0"
],
"statement": "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."
}claims · versions.catalogue-boundary
{
"claim_id": "versions.catalogue-boundary",
"limits": "First observed release is a lower bound, not precise behavioral introduction.",
"method": "Read locked catalogue facts and definition snapshot.",
"position": 2,
"runtime": [],
"sources": [
"src.errcodes.42P13.18.6"
],
"statement": "Locked catalogue snapshots show this condition by PostgreSQL 7.4; source behavior here is fixed at PostgreSQL 18.6."
}messages · message.variant-1
{
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"message_id": "message.variant-1",
"path": "",
"position": 0,
"raw": {
"detail_templates": [
"%s"
],
"hint_templates": [],
"id": "message.variant-1",
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"primary_template": "cannot determine transition data type",
"roles": [
{
"role": "errmsg",
"template": "cannot determine transition data type"
},
{
"role": "errdetail_internal",
"template": "%s"
}
],
"severity_source": "ERROR",
"sources": [
"src.call.42P13.59b4e33cdd3e899e2a030829"
],
"sqlstate": "42P13"
},
"severity": "ERROR",
"sources": [
"src.call.42P13.59b4e33cdd3e899e2a030829"
],
"templates": [
{
"kind": "primary",
"literal": "cannot determine transition data type",
"position": 0,
"role": "",
"template": "cannot determine transition data type"
},
{
"kind": "detail",
"literal": "",
"position": 1,
"role": "",
"template": "%s"
},
{
"kind": "primary",
"literal": "",
"position": 2,
"role": "errdetail_internal",
"template": "%s"
}
]
}messages · message.variant-2
{
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"message_id": "message.variant-2",
"path": "",
"position": 1,
"raw": {
"detail_templates": [
"Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING."
],
"hint_templates": [],
"id": "message.variant-2",
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"primary_template": "return type mismatch in function declared to return %s",
"roles": [
{
"role": "errmsg",
"template": "return type mismatch in function declared to return %s"
},
{
"role": "errdetail",
"template": "Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING."
}
],
"severity_source": "ERROR",
"sources": [
"src.call.42P13.2ffff7c5778d60ac8f47ff67"
],
"sqlstate": "42P13"
},
"severity": "ERROR",
"sources": [
"src.call.42P13.2ffff7c5778d60ac8f47ff67"
],
"templates": [
{
"kind": "primary",
"literal": "return type mismatch in function declared to return",
"position": 0,
"role": "",
"template": "return type mismatch in function declared to return %s"
},
{
"kind": "detail",
"literal": "Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING.",
"position": 1,
"role": "",
"template": "Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING."
},
{
"kind": "primary",
"literal": "Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING.",
"position": 2,
"role": "errdetail",
"template": "Function's final statement must be SELECT or INSERT/UPDATE/DELETE/MERGE RETURNING."
}
]
}messages · message.variant-3
{
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"message_id": "message.variant-3",
"path": "",
"position": 2,
"raw": {
"detail_templates": [],
"hint_templates": [
"The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead."
],
"id": "message.variant-3",
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"primary_template": "trigger functions cannot have declared arguments",
"roles": [
{
"role": "errmsg",
"template": "trigger functions cannot have declared arguments"
},
{
"role": "errhint",
"template": "The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead."
}
],
"severity_source": "ERROR",
"sources": [
"src.call.42P13.1f3147b83dd1ece95cf5aaf0"
],
"sqlstate": "42P13"
},
"severity": "ERROR",
"sources": [
"src.call.42P13.1f3147b83dd1ece95cf5aaf0"
],
"templates": [
{
"kind": "primary",
"literal": "trigger functions cannot have declared arguments",
"position": 0,
"role": "",
"template": "trigger functions cannot have declared arguments"
},
{
"kind": "hint",
"literal": "The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.",
"position": 1,
"role": "",
"template": "The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead."
},
{
"kind": "primary",
"literal": "The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.",
"position": 2,
"role": "errhint",
"template": "The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead."
}
]
}sources · src.errcodes.42P13.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "line 394",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.42P13.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L394"
}sources · src.call.42P13.59b4e33cdd3e899e2a030829
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 142-145",
"path": "src/backend/catalog/pg_aggregate.c",
"position": 1,
"sha256": "75c08cdd82917e45647f7c523c9ad8fb49423c89f13e26754be1e37e4c6a49b4",
"source_id": "src.call.42P13.59b4e33cdd3e899e2a030829",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/pg_aggregate.c#L142-L145"
}sources · src.call.42P13.2ffff7c5778d60ac8f47ff67
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 2222-2226",
"path": "src/backend/executor/functions.c",
"position": 2,
"sha256": "ea37a18fab0f741445874b63e239027ff3901273a9d8e2046be321d3c021a604",
"source_id": "src.call.42P13.2ffff7c5778d60ac8f47ff67",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/functions.c#L2222-L2226"
}sources · src.call.42P13.1f3147b83dd1ece95cf5aaf0
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 493-496",
"path": "src/pl/plpgsql/src/pl_comp.c",
"position": 3,
"sha256": "1da6339c6a538df3045d02326c96d9afe3447c68173ebee0aefee0bca3a2ae09",
"source_id": "src.call.42P13.1f3147b83dd1ece95cf5aaf0",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/pl/plpgsql/src/pl_comp.c#L493-L496"
}sources · src.calls.REL_18_6.42P13
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "",
"path": "raw/calls/REL_18_6.jsonl",
"position": 4,
"sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
"source_id": "src.calls.REL_18_6.42P13",
"tag": "",
"url": ""
}Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · english-manuals:a765eee11ff85f6a86bec5dfa972a47d787bd329066628e057fd4fd7d08b3cbc
Text language: en · english-manuals:a765eee11ff85f6a86bec5dfa972a47d787bd329066628e057fd4fd7d08b3cbc