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

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

Wiki / SQLSTATE

22036 — non_numeric_sql_json_item

JSON 路径项方法收到非数值的项。

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

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

aliases
未知
class name
Data Exception
condition name
non_numeric_sql_json_item
lang
en
sqlstate
22036

版本定义 PG 18

22036

速览 {#at-a-glance}

JSON 路径项方法收到的值不满足数值或转换约束。固定路径覆盖 .number()、.decimal()、.integer()、.bigint()、.double()、.boolean()、.abs()、.floor()、.ceiling(),以及 .string() 的相应类型检查。

报文 {#messages}

固定 jsonpath 方法的代表性首要报文如下:

| 触发条件 | 首要报文 | | --- | --- | | .abs()、.floor() 或 .ceiling() 收到非数值项 | jsonpath item method .%s() can only be applied to a numeric value | | 转换方法收到的既不是字符串也不是数值项 | jsonpath item method .%s() can only be applied to a string or numeric value | | .boolean() 收到不支持的项 | jsonpath item method .%s() can only be applied to a boolean, string, or numeric value | | 字符串或数值不能转换为目标类型 | argument "%s" of jsonpath item method .%s() is invalid for type %s | | 数值转换得到 NaN 或 Infinity | NaN or Infinity is not allowed for jsonpath item method .%s() | | .string() 收到不支持的项 | jsonpath item method .%s() can only be applied to a boolean, string, numeric, or datetime value |

含义 {#meaning}

jsonpath 执行器会按输入类型分派各项方法。.integer()、.bigint()、.double() 以及 .number()/.decimal() 处理字符串输入时,会使用目标输入例程或数值解析,并通过 ErrorSaveContext 或显式错误标志记录失败。已有数值项走各自分支:.number() 可直接保留数值,.integer() 和 .bigint() 使用 numeric_int4_opt_error/numeric_int8_opt_error,.decimal() 再应用精度/小数位 typmod。.boolean() 直接接受布尔值,用 int4in 转换数值,用 parse_bool 解析字符串;.abs()、.floor() 和 .ceiling() 要求数值标量。数值和 double 路径拒绝 NaN 或 Infinity。.string() 的约束更宽,可接受布尔、字符串、数值或日期时间项;只有路径模式允许时才会解包数组。

诊断 {#diagnosis}

查看首要报文中的方法名、项类型和值。区分字符串解析和已有数值项:.number() 可直接处理已有数值,.integer()/.bigint() 做数值范围检查,.decimal() 可能应用精度/小数位 typmod,.boolean() 有直接、数值和 parse_bool 分支。对象、数组或不支持的项属于类型问题。若方法拒绝非有限数值,应在调用前移除或拦截它。不要把 make_numeric_typmod_safe 的所有底层精度/小数位诊断都归为 22036,只保留已展示的 jsonpath 报错分支。不要把本码与一元算术操作数检查条件 2203B,或 JSON 路径日期时间方法 22031 混淆。

处理 {#response}

修改路径以选中预期标量,在转换前规范化文档,或改用符合该值输入约束的方法。若源数据可能变化,应在调用方法前验证数值文本和有限性。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的动作。

版本 {#versions}

锁定目录从 12.0 起记录该条件;固定的转换和项方法路径来自 PostgreSQL 18.6。本页未声称有自然运行观察。

相关 {#related}

2203B、22031、22038

来源 {#sources}

数值项方法检查条件见 jsonpath_exec.c#L1129-1588,.string() 类型约束见 #L1592-1647,只接受数值的方法见 #L2280-2310。strict/lax 与抛出/返回宏见 #L235-249。结构化证据记录绑定这些检查条件和报文;本页未运行自然案例。

比较版本

SQLSTATE 证据与已记录的运行版本

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read fixed definition.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "22036 is non_numeric_sql_json_item in SQLSTATE Class 22."
}
claims · resolved-path
{
  "claim_id": "resolved-path",
  "limits": "Source confirmation is not a natural runtime observation.",
  "method": "Read the complete representative numeric, string, and unary numeric item-method guards.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.jsonpath.numeric-methods",
    "src.jsonpath.string-method",
    "src.jsonpath.numeric-unary-method",
    "src.jsonpath.context-flags",
    "src.jsonpath.execute-context"
  ],
  "statement": "The fixed jsonpath numeric item-method branches dispatch by input type. String inputs for .integer(), .bigint(), .double(), and the string side of .number()/.decimal() use target input or numeric parsing with ErrorSaveContext or an explicit error flag. Existing numeric items use method-specific paths: .number() can keep the numeric value, .integer() and .bigint() use numeric_int4_opt_error/numeric_int8_opt_error, and .decimal() applies its precision/scale typmod. .boolean() accepts a boolean directly, converts numeric input through int4in, and parses strings with parse_bool. Numeric-only methods reject nonnumeric items; .string() accepts boolean, string, numeric, or datetime items. Non-finite values are rejected by the shown numeric/double branches. Source confirmation is not a natural runtime observation."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue boundary.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 22036 from 12.0 without proving exact implementation introduction."
}
messages · message.numeric-only
{
  "limits": "",
  "message_id": "message.numeric-only",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.numeric-only",
    "primary_template": "jsonpath item method .%s() can only be applied to a numeric value",
    "severity_source": "ERROR",
    "sources": [
      "src.jsonpath.numeric-unary-method"
    ],
    "sqlstate": "22036"
  },
  "severity": "ERROR",
  "sources": [
    "src.jsonpath.numeric-unary-method"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "jsonpath item method . () can only be applied to a numeric value",
      "position": 0,
      "role": "",
      "template": "jsonpath item method .%s() can only be applied to a numeric value"
    }
  ]
}
messages · message.string-or-numeric
{
  "limits": "",
  "message_id": "message.string-or-numeric",
  "path": "",
  "position": 1,
  "raw": {
    "id": "message.string-or-numeric",
    "primary_template": "jsonpath item method .%s() can only be applied to a string or numeric value",
    "severity_source": "ERROR",
    "sources": [
      "src.jsonpath.numeric-methods"
    ],
    "sqlstate": "22036"
  },
  "severity": "ERROR",
  "sources": [
    "src.jsonpath.numeric-methods"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "jsonpath item method . () can only be applied to a string or numeric value",
      "position": 0,
      "role": "",
      "template": "jsonpath item method .%s() can only be applied to a string or numeric value"
    }
  ]
}
messages · message.boolean-method
{
  "limits": "",
  "message_id": "message.boolean-method",
  "path": "",
  "position": 2,
  "raw": {
    "id": "message.boolean-method",
    "primary_template": "jsonpath item method .%s() can only be applied to a boolean, string, or numeric value",
    "severity_source": "ERROR",
    "sources": [
      "src.jsonpath.numeric-methods"
    ],
    "sqlstate": "22036"
  },
  "severity": "ERROR",
  "sources": [
    "src.jsonpath.numeric-methods"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "jsonpath item method . () can only be applied to a boolean, string, or numeric value",
      "position": 0,
      "role": "",
      "template": "jsonpath item method .%s() can only be applied to a boolean, string, or numeric value"
    }
  ]
}
messages · message.invalid-type
{
  "limits": "",
  "message_id": "message.invalid-type",
  "path": "",
  "position": 3,
  "raw": {
    "id": "message.invalid-type",
    "primary_template": "argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
    "severity_source": "ERROR",
    "sources": [
      "src.jsonpath.numeric-methods"
    ],
    "sqlstate": "22036"
  },
  "severity": "ERROR",
  "sources": [
    "src.jsonpath.numeric-methods"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "argument \" \" of jsonpath item method . () is invalid for type",
      "position": 0,
      "role": "",
      "template": "argument \"%s\" of jsonpath item method .%s() is invalid for type %s"
    }
  ]
}
messages · message.nan-infinity
{
  "limits": "",
  "message_id": "message.nan-infinity",
  "path": "",
  "position": 4,
  "raw": {
    "id": "message.nan-infinity",
    "primary_template": "NaN or Infinity is not allowed for jsonpath item method .%s()",
    "severity_source": "ERROR",
    "sources": [
      "src.jsonpath.numeric-methods"
    ],
    "sqlstate": "22036"
  },
  "severity": "ERROR",
  "sources": [
    "src.jsonpath.numeric-methods"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "NaN or Infinity is not allowed for jsonpath item method . ()",
      "position": 0,
      "role": "",
      "template": "NaN or Infinity is not allowed for jsonpath item method .%s()"
    }
  ]
}
messages · message.string-method
{
  "limits": "",
  "message_id": "message.string-method",
  "path": "",
  "position": 5,
  "raw": {
    "id": "message.string-method",
    "primary_template": "jsonpath item method .%s() can only be applied to a boolean, string, numeric, or datetime value",
    "severity_source": "ERROR",
    "sources": [
      "src.jsonpath.string-method"
    ],
    "sqlstate": "22036"
  },
  "severity": "ERROR",
  "sources": [
    "src.jsonpath.string-method"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "jsonpath item method . () can only be applied to a boolean, string, numeric, or datetime value",
      "position": 0,
      "role": "",
      "template": "jsonpath item method .%s() can only be applied to a boolean, string, numeric, or datetime value"
    }
  ]
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L221"
}
sources · src.jsonpath.numeric-methods
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/jsonpath_exec.c",
  "position": 1,
  "sha256": "678cb8947f0b5e6ad14524f1863987ab99641cfb5f81121fc5c5006af0319d02",
  "source_id": "src.jsonpath.numeric-methods",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonpath_exec.c#L1129"
}
sources · src.jsonpath.string-method
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/jsonpath_exec.c",
  "position": 2,
  "sha256": "678cb8947f0b5e6ad14524f1863987ab99641cfb5f81121fc5c5006af0319d02",
  "source_id": "src.jsonpath.string-method",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonpath_exec.c#L1592"
}
sources · src.jsonpath.numeric-unary-method
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/jsonpath_exec.c",
  "position": 3,
  "sha256": "678cb8947f0b5e6ad14524f1863987ab99641cfb5f81121fc5c5006af0319d02",
  "source_id": "src.jsonpath.numeric-unary-method",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonpath_exec.c#L2280"
}
sources · src.jsonpath.context-flags
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/jsonpath_exec.c",
  "position": 4,
  "sha256": "678cb8947f0b5e6ad14524f1863987ab99641cfb5f81121fc5c5006af0319d02",
  "source_id": "src.jsonpath.context-flags",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonpath_exec.c#L235"
}
sources · src.jsonpath.execute-context
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/jsonpath_exec.c",
  "position": 5,
  "sha256": "678cb8947f0b5e6ad14524f1863987ab99641cfb5f81121fc5c5006af0319d02",
  "source_id": "src.jsonpath.execute-context",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/jsonpath_exec.c#L654"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:86fe9299120780201087bfc35bb47250ad772b29dc742a1baac2aa5c43ff15ef

正文语言: zh-Hans · english-manuals:86fe9299120780201087bfc35bb47250ad772b29dc742a1baac2aa5c43ff15ef