↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

42P13 — 无效函数定义

函数、聚合或触发器声明在校验阶段失败。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Syntax Error or Access Rule Violation
condition name
invalid_function_definition
lang
en
sqlstate
42P13

版本定义 PG 18

42P13 — 无效函数定义

速览 {#at-a-glance}

42P13(invalid_function_definition)函数、聚合和触发器声明可能在执行前校验失败。

含义 {#meaning}

函数定义校验在声明不兼容时使用此条件。选定的核心路径包括无法确定多态聚合转换类型(DETAIL 由调用方动态生成)、最终语句不是兼容的 SELECT 或 DML RETURNING 而导致返回类型不匹配,以及触发器函数声明参数。

诊断 {#diagnosis}

修改函数前先按消息分类:聚合转换类型推断及其动态 DETAIL、最终语句/RETURNING 结果与声明返回类型不一致,或触发器函数声明参数。把已存签名、返回类型与函数体和触发器约定逐项比较;不返回行的 DML 或 utility 命令与标量强制转换失败属于不同的最终语句路径。

处理 {#response}

修正消息指出的声明或函数体:为聚合提供可确定的转换类型,让函数最后语句返回声明类型;触发器参数应通过 TG_NARGS/TG_ARGV 读取,不能在声明中列出。检查依赖调用者后再重建或替换。如果 ERROR 发生在显式事务中,执行下一条 DDL 前先 ROLLBACK,或回滚到错误前的保存点。

消息 {#messages}

固定源码中的代表性消息包括: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.。占位符由实际对象、列或参数填充。

版本 {#versions}

锁定目录显示该条件最早见于 PostgreSQL 7.4;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。

相关 {#related}

来源 {#sources}

源码消息、行号和证据边界见 作者证据。

比较版本

SQLSTATE 证据与已记录的运行版本

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": ""
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:a765eee11ff85f6a86bec5dfa972a47d787bd329066628e057fd4fd7d08b3cbc

正文语言: zh-Hans · english-manuals:a765eee11ff85f6a86bec5dfa972a47d787bd329066628e057fd4fd7d08b3cbc