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

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

Wiki / SQLSTATE

42P18 — 无法确定数据类型

无法推断表达式或参数的数据类型。

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

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

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

版本定义 PG 18

42P18 — 无法确定数据类型

速览 {#at-a-glance}

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

含义 {#meaning}

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

诊断 {#diagnosis}

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

处理 {#response}

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

消息 {#messages}

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

版本 {#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.42P18.18.6"
  ],
  "statement": "42P18 is the indeterminate_datatype 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.42P18.24454306029f6c5a510a8800",
    "src.call.42P18.8fe85a04bb8a03d1fe617f46"
  ],
  "statement": "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."
}
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.42P18.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": [],
    "hint_templates": [
      "Explicitly cast to the desired type, for example ARRAY[]::integer[]."
    ],
    "id": "message.variant-1",
    "limits": "Placeholders remain dynamic source fields; no concrete runtime value is claimed.",
    "primary_template": "cannot determine type of empty array",
    "roles": [
      {
        "role": "errmsg",
        "template": "cannot determine type of empty array"
      },
      {
        "role": "errhint",
        "template": "Explicitly cast to the desired type, for example ARRAY[]::integer[]."
      }
    ],
    "severity_source": "ERROR",
    "sources": [
      "src.call.42P18.24454306029f6c5a510a8800"
    ],
    "sqlstate": "42P18"
  },
  "severity": "ERROR",
  "sources": [
    "src.call.42P18.24454306029f6c5a510a8800"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "cannot determine type of empty array",
      "position": 0,
      "role": "",
      "template": "cannot determine type of empty array"
    },
    {
      "kind": "hint",
      "literal": "Explicitly cast to the desired type, for example ARRAY[]::integer[].",
      "position": 1,
      "role": "",
      "template": "Explicitly cast to the desired type, for example ARRAY[]::integer[]."
    },
    {
      "kind": "primary",
      "literal": "Explicitly cast to the desired type, for example ARRAY[]::integer[].",
      "position": 2,
      "role": "errhint",
      "template": "Explicitly cast to the desired type, for example ARRAY[]::integer[]."
    }
  ]
}
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": "ERROR",
    "sources": [
      "src.call.42P18.8fe85a04bb8a03d1fe617f46"
    ],
    "sqlstate": "42P18"
  },
  "severity": "ERROR",
  "sources": [
    "src.call.42P18.8fe85a04bb8a03d1fe617f46"
  ],
  "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.42P18.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "line 351",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.42P18.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L351"
}
sources · src.call.42P18.24454306029f6c5a510a8800
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 2102-2107",
  "path": "src/backend/parser/parse_expr.c",
  "position": 1,
  "sha256": "63c37770872a08978f931c31f801666a08e3bc8e51c2c65ff60151a1d139d55b",
  "source_id": "src.call.42P18.24454306029f6c5a510a8800",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_expr.c#L2102-L2107"
}
sources · src.call.42P18.8fe85a04bb8a03d1fe617f46
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "lines 733-736",
  "path": "src/backend/tcop/postgres.c",
  "position": 2,
  "sha256": "9fb62275b1badf94d01ab351337b60410cd9b3ab1fe63fa9f23d6d2185a21061",
  "source_id": "src.call.42P18.8fe85a04bb8a03d1fe617f46",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/tcop/postgres.c#L733-L736"
}
sources · src.calls.REL_18_6.42P18
{
  "commit": "",
  "docs_url": "",
  "kind": "local_artifact",
  "location": "",
  "path": "raw/calls/REL_18_6.jsonl",
  "position": 3,
  "sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
  "source_id": "src.calls.REL_18_6.42P18",
  "tag": "",
  "url": ""
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:99603a59d4f54c191b6d3cb3c7ab3e70f2c04ed103302979c8f3a66b9b4e9020

正文语言: zh-Hans · english-manuals:99603a59d4f54c191b6d3cb3c7ab3e70f2c04ed103302979c8f3a66b9b4e9020