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

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

Wiki / SQLSTATE

42P08 — 参数类型不明确

参数存在但无法推导出一致而具体的类型。

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

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

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

版本定义 PG 18

42P08 — 参数类型不明确

速览 {#at-a-glance}

42P08(ambiguous_parameter)表示参数标记存在,但解析阶段无法把它解析为一致或足够具体的类型。由于相似主消息也可能来自其他条件,必须结合 SQLSTATE 和源码分支判断。

含义 {#meaning}

可变参数强制转换钩子会先为未知参数记录目标类型;后续上下文要求另一类型时,报告 ERROR inconsistent types deduced for parameter $%d,DETAIL 为 %s versus %s。随后参数解析检查发现解析出的类型与外部类型数组不一致时,报告 ERROR could not determine data type of parameter $%d。这是两条选定的 42P08 检查,不是笼统的“绑定失败”。

相同的 could not determine data type of parameter $%d 主消息也会在 postgres.c 的可变参数完成检查中配合 ERRCODE_INDETERMINATE_DATATYPE(42P18)发出。应同时读取 SQLSTATE 和源码路径:本页 42P08 是参数解析阶段的类型不匹配,42P18 是解析完成后仍未确定类型,超出范围的标记则是 42P02。

诊断 {#diagnosis}

记录参数编号、所有表达式上下文和 DETAIL。对于类型不一致分支,对照 DETAIL 中的两种类型,找到分别施加约束的上下文;对于未确定分支,检查 PREPARE/扩展查询的参数类型数组和最终推导类型。缺少标记(42P02)、Bind 数量违反协议(08P01)以及别名/列歧义不应混入此类型解析问题。

处理 {#response}

在明确的表达式边界声明参数类型或转换类型。两个上下文确实需要不同类型时拆分参数,否则统一上下文类型。不要随意转换成宽泛类型,随后核对运算符、索引、NULL 语义和序列化。若 ERROR 发生在显式事务中,应回滚到合适保存点或回滚事务再重试。

消息变体 {#messages}

选定的 42P08 变体均为 ERROR:

| 检查 | 主消息 | DETAIL | | --- | --- | --- | | 推导目标类型冲突 | inconsistent types deduced for parameter $%d | %s versus %s | | 最终参数类型不匹配 | could not determine data type of parameter $%d | 无 |

第二条主消息也可能来自独立的 42P18 未确定类型检查;SQLSTATE 是报文身份的一部分。

版本 {#versions}

目录范围从 7.4 到 18.6、19beta3,不是精确的功能引入判断。选定的是两条 42P08 检查和相邻的 42P18 边界源码,未运行参数案例。

相关 {#related}

来源 {#sources}

  • src.errcodes.42P08.18.6 — src/backend/utils/errcodes.txt line 388,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(源码)。

  • src.call.42P08.c2cfa81ed9389a1bddf8ec41 — src/backend/parser/parse_param.c lines 220-227,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28(源码)。

  • src.call.42P08.18ba6576d169dfdf614df72d — src/backend/parser/parse_param.c lines 308-312,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28(源码)。

  • src.call.42P08.unresolved-boundary — src/backend/tcop/postgres.c lines 725-736,固定于 724edf9bde9d356724ad384a2e196edc3c9f80f7;SHA-256 9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061(源码)。

  • src.calls.REL_18_6.42P08 — 固定本地核心调用扫描;SHA-256 9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf。

  • 作者证据 — 记录源码断言、消息角色和运行边界。

比较版本

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.42P08.18.6"
  ],
  "statement": "42P08 is the ambiguous_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.42P08.c2cfa81ed9389a1bddf8ec41",
    "src.call.42P08.18ba6576d169dfdf614df72d",
    "src.call.42P08.unresolved-boundary"
  ],
  "statement": "The selected 42P08 guards are conflicting inferred types, reporting `inconsistent types deduced for parameter $%d` with DETAIL `%s versus %s`, and a later parameter-resolution mismatch, reporting `could not determine data type of parameter $%d`; both are ERRORs. The same second primary is emitted with 42P18 by the separate var-parameter completion guard when a type remains unknown after analysis, while an out-of-range marker is 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.42P08.18.6"
  ],
  "statement": "From 7.4 through 18.6 and 19beta3; this catalogue range is not a precise introduction claim. The selected two 42P08 guards and nearby 42P18 boundary are fixed 18.6 source paths and no runtime parameter 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": [
      "%s versus %s"
    ],
    "hint_templates": [],
    "id": "message.variant-1",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "inconsistent types deduced for parameter $%d",
    "roles": [
      {
        "role": "errmsg",
        "template": "inconsistent types deduced for parameter $%d"
      },
      {
        "role": "errdetail",
        "template": "%s versus %s"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P08.c2cfa81ed9389a1bddf8ec41"
    ],
    "sqlstate": "42P08"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P08.c2cfa81ed9389a1bddf8ec41"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "inconsistent types deduced for parameter $",
      "position": 0,
      "role": "",
      "template": "inconsistent types deduced for parameter $%d"
    },
    {
      "kind": "detail",
      "literal": "versus",
      "position": 1,
      "role": "",
      "template": "%s versus %s"
    },
    {
      "kind": "primary",
      "literal": "versus",
      "position": 2,
      "role": "errdetail",
      "template": "%s versus %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": [],
    "hint_templates": [],
    "id": "message.variant-2",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "could not determine data type of parameter $%d",
    "roles": [
      {
        "role": "errmsg",
        "template": "could not determine data type of parameter $%d"
      }
    ],
    "severity_source": "explicit ERROR",
    "sources": [
      "src.call.42P08.18ba6576d169dfdf614df72d"
    ],
    "sqlstate": "42P08"
  },
  "severity": "explicit ERROR",
  "sources": [
    "src.call.42P08.18ba6576d169dfdf614df72d"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "could not determine data type of parameter $",
      "position": 0,
      "role": "",
      "template": "could not determine data type of parameter $%d"
    }
  ]
}
sources · src.errcodes.42P08.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "line 388",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.42P08.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L388"
}
sources · src.call.42P08.c2cfa81ed9389a1bddf8ec41
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 220-227",
  "path": "src/backend/parser/parse_param.c",
  "position": 1,
  "sha256": "4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28",
  "source_id": "src.call.42P08.c2cfa81ed9389a1bddf8ec41",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_param.c#L220-L227"
}
sources · src.call.42P08.18ba6576d169dfdf614df72d
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 308-312",
  "path": "src/backend/parser/parse_param.c",
  "position": 2,
  "sha256": "4aab2ecc770fcda619b26ac12beaf7e527542b56f55eb45879b72e92442e8a28",
  "source_id": "src.call.42P08.18ba6576d169dfdf614df72d",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_param.c#L308-L312"
}
sources · src.call.42P08.unresolved-boundary
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 725-736",
  "path": "src/backend/tcop/postgres.c",
  "position": 3,
  "sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
  "source_id": "src.call.42P08.unresolved-boundary",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L725-L736"
}
sources · src.calls.REL_18_6.42P08
{
  "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.42P08",
  "tag": "",
  "url": ""
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:6ffa6b61afc02e941ff4b656ec7f118ce6739e4ba078946098c784c9176fe3c7

正文语言: zh-Hans · english-manuals:6ffa6b61afc02e941ff4b656ec7f118ce6739e4ba078946098c784c9176fe3c7