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

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

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

42P18 indeterminate_datatype

无法确定数据类型

ERROR 源码确认 详解 未实测

条件名
indeterminate_datatype
宏名称
ERRCODE_INDETERMINATE_DATATYPE
启用版本
7.4
状态
活跃

版本覆盖

速览

42P18indeterminate_datatype)表达式或协议参数没有确定类型时,类型推断会失败。

含义

解析器无法为表达式或协议参数确定唯一类型。18.6 核心明确报告空 ARRAY[]pg_analyze_and_rewrite_varparams 还会在最后检查每个仍为 InvalidOidUNKNOWNOID 的参数,例如没有任何上下文约束的 $1。这不同于 42P08(输入暗示了互相不兼容的类型)和 42P02(参数引用本身不存在)。

诊断

根据响应中的位置或参数编号定位问题。对于 ARRAY[],检查周围表达式并转换到预期元素类型;对于 $n,检查 Parse/扩展查询的参数类型以及应当约束它的所有上下文,再确认最后的参数类型检查能够得到 OID。客户端不发送类型 OID 时,服务器可能无法完成推断。互相冲突的推断属于 42P08;引用未声明参数属于 42P02。

处理

添加语义正确的显式转换或参数类型信息,然后确认运算符和结果列仍是预期类型。不要把所有值都转成 text 来掩盖错误,这会改变索引使用以及函数/运算符选择;确认定义修正后再重试解析或语句。如果 ERROR 发生在显式事务中,发送修正语句前先 ROLLBACK 或回滚到错误前的保存点。

消息

固定源码中的代表性消息包括:message: cannot determine type of empty array; HINT: Explicitly cast to the desired type, for example ARRAY[]::integer[].;message: could not determine data type of parameter $%d。占位符由实际对象、列或参数填充。

报文模板

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

主消息 cannot determine type of empty array
HINT Explicitly cast to the desired type, for example ARRAY[]::integer[].
主消息 · errhint Explicitly cast to the desired type, for example ARRAY[]::integer[].

来源:src/backend/parser/parse_expr.c(lines 2102-2107) @ REL_18_6

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

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

来源:src/backend/tcop/postgres.c(lines 733-736) @ REL_18_6

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

版本

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

来源

证据

断言

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

  • 42P18 is the indeterminate_datatype 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 351)

  • Core 18.6 reports empty ARRAY[] and, in pg_analyze_and_rewrite_varparams, rejects every parameter left InvalidOid or UNKNOWNOID after parse analysis, such as $1 with no constraining context. This is distinct from 42P08 conflicting deductions and 42P02 missing parameter references.

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

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

    来源src/backend/parser/parse_expr.c(lines 2102-2107) · src/backend/tcop/postgres.c(lines 733-736)

  • Locked catalogue snapshots show this condition by PostgreSQL 7.4; source behavior here is fixed at PostgreSQL 18.6.

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

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

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

同类错误代码

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