42P02 — 未定义参数
查询引用了解析器未知的位置参数,如 $1。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Syntax Error or Access Rule Violation
- condition name
- undefined_parameter
- lang
- en
- sqlstate
- 42P02
版本定义 PG 18
42P02 — 未定义参数
速览 {#at-a-glance}
42P02(undefined_parameter)是解析阶段的 ERROR:$1 等位置参数超出了解析器已知的参数集合。它不同于 Bind 报文参数数量违反协议时的 08P01,也不同于参数存在但类型推导不一致的 42P08。
含义 {#meaning}
固定参数钩子会拒绝超出声明数组或类型无效的参数编号;可变参数钩子虽然会在解析时扩展数组,解析结束时仍会拒绝超出范围的参数。没有钩子解析该标记时也使用相同主消息。选定路径都带解析位置,there is no parameter $%d 中的编号是动态值;这针对 SQL 参数标记,不是表列或 PL/pgSQL 变量缺失。
扩展查询的边界不同:exec_bind_message 会检查参数格式码数量、参数值数量和预备语句的要求,数量不符时报告 08P01,例如 bind message supplies %d parameters, but prepared statement "%s" requires %d。因此 Bind 阶段的数量/格式错误不能改标成 42P02。
诊断 {#diagnosis}
记录 SQL 文本、解析位置、参数编号和协议阶段。Parse/解析阶段对照固定或可变参数声明与每个 $n;扩展查询 Bind 阶段另查格式码和参数值数量,数量不符走 08P01。参数存在但类型推导冲突时才看 42P08。
处理 {#response}
修正 SQL 占位符编号或 Parse 参数声明;Bind 阶段发送预备语句要求的准确参数数量和兼容的格式码,不要用类型转换掩盖数量错误。真正缺少参数时补上预期参数,或明确改用字面量/默认值。若 ERROR 发生在显式事务中,应回滚到合适保存点或回滚事务后重试;本页没有运行时恢复观察。
消息变体 {#messages}
选定解析路径均为 ERROR there is no parameter $%d;%d 是动态参数编号。固定的 18.6 Bind 检查属于 08P01,主消息是 bind message has %d parameter formats but %d parameters 或 bind message supplies %d parameters, but prepared statement "%s" requires %d。
版本 {#versions}
目录锁定范围从 7.4 下界到 18.6、19beta3;这是目录范围,不是运行时比较。选定的是 18.6 固定解析器和 Bind 源码路径,未运行客户端 Bind 案例。
相关 {#related}
来源 {#sources}
-
src.errcodes.42P02.18.6—src/backend/utils/errcodes.txtline 375,固定于724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(源码)。 -
src.call.42P02.81f0048a16f439569ce3a4ba—src/backend/parser/parse_expr.clines 899-902,固定于724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-25663c37770872a08978f931c31f801666a08e3bc8e51c2c65ff60151a1d139d55b(源码)。 -
src.call.42P02.73515542f469d69893fd5fb8—src/backend/parser/parse_param.clines 109-112,固定于724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-2564aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28(源码)。 -
src.call.42P02.671f865f9d428e0ab2a78347—src/backend/parser/parse_param.clines 203-206,固定于724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-2564aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28(源码)。 -
src.call.42P02.bind-contract—src/backend/tcop/postgres.clines 1718-1731,固定于724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-2569fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061(源码)。 -
src.calls.REL_18_6.42P02— 固定本地核心调用扫描;SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf。 -
作者证据— 记录源码断言、消息角色和运行边界。
比较版本
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.42P02.18.6"
],
"statement": "42P02 is the undefined_parameter 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 complete resolved REL_18_6 report groups and message roles.",
"position": 1,
"runtime": [],
"sources": [
"src.call.42P02.81f0048a16f439569ce3a4ba",
"src.call.42P02.73515542f469d69893fd5fb8",
"src.call.42P02.671f865f9d428e0ab2a78347",
"src.call.42P02.bind-contract"
],
"statement": "Fixed and variable parser parameter hooks report `there is no parameter $%d` with parser position when a marker is outside the known parameter set. The separate extended-query Bind guards report protocol violation 08P01 for parameter format/value counts that do not match the prepared statement, so a Bind count mismatch is not 42P02."
}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 snapshots.",
"position": 2,
"runtime": [],
"sources": [
"src.errcodes.42P02.18.6"
],
"statement": "From the locked 7.4 lower bound through 18.6 and 19beta3; this is a catalogue range. The selected parser and Bind branches are fixed 18.6 source paths and no client bind case was run."
}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": [],
"hint_templates": [],
"id": "message.variant-1",
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"primary_template": "there is no parameter $%d",
"roles": [
{
"role": "errmsg",
"template": "there is no parameter $%d"
}
],
"severity_source": "explicit ERROR",
"sources": [
"src.call.42P02.81f0048a16f439569ce3a4ba"
],
"sqlstate": "42P02"
},
"severity": "explicit ERROR",
"sources": [
"src.call.42P02.81f0048a16f439569ce3a4ba"
],
"templates": [
{
"kind": "primary",
"literal": "there is no parameter $",
"position": 0,
"role": "",
"template": "there is no parameter $%d"
}
]
}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": [],
"hint_templates": [],
"id": "message.variant-2",
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"primary_template": "there is no parameter $%d",
"roles": [
{
"role": "errmsg",
"template": "there is no parameter $%d"
}
],
"severity_source": "explicit ERROR",
"sources": [
"src.call.42P02.73515542f469d69893fd5fb8"
],
"sqlstate": "42P02"
},
"severity": "explicit ERROR",
"sources": [
"src.call.42P02.73515542f469d69893fd5fb8"
],
"templates": [
{
"kind": "primary",
"literal": "there is no parameter $",
"position": 0,
"role": "",
"template": "there is no parameter $%d"
}
]
}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": [],
"id": "message.variant-3",
"limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
"primary_template": "there is no parameter $%d",
"roles": [
{
"role": "errmsg",
"template": "there is no parameter $%d"
}
],
"severity_source": "explicit ERROR",
"sources": [
"src.call.42P02.671f865f9d428e0ab2a78347"
],
"sqlstate": "42P02"
},
"severity": "explicit ERROR",
"sources": [
"src.call.42P02.671f865f9d428e0ab2a78347"
],
"templates": [
{
"kind": "primary",
"literal": "there is no parameter $",
"position": 0,
"role": "",
"template": "there is no parameter $%d"
}
]
}sources · src.errcodes.42P02.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "line 375",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.42P02.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L375"
}sources · src.call.42P02.81f0048a16f439569ce3a4ba
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 899-902",
"path": "src/backend/parser/parse_expr.c",
"position": 1,
"sha256": "63c37770872a08978f931c31f801666a08e3bc8e51c2c65ff60151a1d139d55b",
"source_id": "src.call.42P02.81f0048a16f439569ce3a4ba",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_expr.c#L899-L902"
}sources · src.call.42P02.73515542f469d69893fd5fb8
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 109-112",
"path": "src/backend/parser/parse_param.c",
"position": 2,
"sha256": "4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28",
"source_id": "src.call.42P02.73515542f469d69893fd5fb8",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_param.c#L109-L112"
}sources · src.call.42P02.671f865f9d428e0ab2a78347
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 203-206",
"path": "src/backend/parser/parse_param.c",
"position": 3,
"sha256": "4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28",
"source_id": "src.call.42P02.671f865f9d428e0ab2a78347",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_param.c#L203-L206"
}sources · src.call.42P02.bind-contract
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "lines 1718-1731",
"path": "src/backend/tcop/postgres.c",
"position": 4,
"sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
"source_id": "src.call.42P02.bind-contract",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L1718-L1731"
}sources · src.calls.REL_18_6.42P02
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "",
"path": "raw/calls/REL_18_6.jsonl",
"position": 5,
"sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
"source_id": "src.calls.REL_18_6.42P02",
"tag": "",
"url": ""
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:6832f8931981680f813099537998b83c507a976b00aa7f51fbfc4c022c1d0d69
正文语言: zh-Hans · english-manuals:6832f8931981680f813099537998b83c507a976b00aa7f51fbfc4c022c1d0d69