选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 42 语法错误或访问规则冲突

42P08 ambiguous_parameter

参数类型不明确

ERROR 源码确认 详解 未实测

条件名
ambiguous_parameter
宏名称
ERRCODE_AMBIGUOUS_PARAMETER
启用版本
7.4
状态
活跃

版本覆盖

速览

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

含义

可变参数强制转换钩子会先为未知参数记录目标类型;后续上下文要求另一类型时,报告 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_DATATYPE42P18)发出。应同时读取 SQLSTATE 和源码路径:本页 42P08 是参数解析阶段的类型不匹配,42P18 是解析完成后仍未确定类型,超出范围的标记则是 42P02

诊断

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

处理

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

消息变体

选定的 42P08 变体均为 ERROR

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

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

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 inconsistent types deduced for parameter $%d
DETAIL %s versus %s
主消息 · errdetail %s versus %s

来源:src/backend/parser/parse_param.c(lines 220-227) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 could not determine data type of parameter $%d

来源:src/backend/parser/parse_param.c(lines 308-312) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

版本

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

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

  • 42P08 is the ambiguous_parameter condition in Class 42.

    核实方式Read fixed REL_18_6 errcodes.txt and locked facts.

    不覆盖Identity does not enumerate all source branches or client failures.

    来源src/backend/utils/errcodes.txt(line 388)

  • 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.

    核实方式Read complete resolved REL_18_6 report groups and message roles.

    不覆盖Representative confirmed core paths only; not exhaustive historical or extension coverage.

    来源src/backend/parser/parse_param.c(lines 220-227) · src/backend/parser/parse_param.c(lines 308-312) · src/backend/tcop/postgres.c(lines 725-736)

  • 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.

    核实方式Read locked catalogue facts and definition snapshots.

    不覆盖First observed release is a lower bound, not precise behavioral introduction.

    来源src/backend/utils/errcodes.txt(line 388)

同类错误代码

Class 42 语法错误或访问规则冲突 下的其他成员。