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

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

百科 / 错误代码 / Class 22 数据异常

22033 invalid_sql_json_subscript

ERROR 源码确认 参考 未实测

类别
Class 22 数据异常
严重等级
ERROR
条件名
invalid_sql_json_subscript
宏名称
ERRCODE_INVALID_SQL_JSON_SUBSCRIPT
启用版本
12
状态
活跃

版本覆盖

速览

SQL/JSON 数组下标无效。固定 jsonpath 路径区分越界、非单一数值和整数范围变体。

报文

固定下标守卫使用以下首要文本:

守卫 首要文本
下标不是单个数值项 jsonpath array subscript is not a single numeric value
数值下标超出 int32 jsonpath array subscript is out of integer range
strict 数组边界失败 jsonpath array subscript is out of bounds

报文模板

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

主消息 jsonpath array subscript is out of bounds

来源:src/backend/utils/adt/jsonpath_exec.c @ REL_18_6

主消息 jsonpath array subscript is not a single numeric value

来源:src/backend/utils/adt/jsonpath_exec.c @ REL_18_6

主消息 jsonpath array subscript is out of integer range

来源:src/backend/utils/adt/jsonpath_exec.c @ REL_18_6

含义

jsonpath 执行器把每个下标表达式求值为结果列表。getArrayIndex 要求结果恰好是一个数值标量,将其截断为整数;结果不是单个数值项或无法符合整数范围时报告 22033。随后数组边界守卫在 strict 模式下对负起点、反向范围或超过数组上界的终点报告同一码。lax 模式会忽略这种结构性越界错误,并把范围限制到现有数组;它不会把非数值或溢出的下标变成有效下标。

诊断

先检查下标表达式的基数和类型,再检查数组长度。表达式返回多个项、非数值或整数溢出时使用转换报文;数值下标或范围违反 strict 数组边界时使用越界报文。记录 path 是 strict 还是 lax,因为 lax 的结构处理可能产生空结果或被限制的结果,而不是 ERROR。后续 SQL/JSON 操作若选择对无项抛错,则属于 22035。

处理

使下标表达式返回整数范围内的单个有限数值,并在 strict 模式下保持目标数组边界内且范围不反向。如果有意使用 lax 的限制或空结果,应确认 path 模式和外层 SQL/JSON 行为确实表达了该意图。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的表达式。

版本

锁定目录从 12.0 起记录该条件;本页固定 jsonpath 源码路径为 PostgreSQL 18.6。未声称本页有自然运行观察。

来源

证据

断言

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

  • 22033 is invalid_sql_json_subscript in SQLSTATE Class 22.

    核实方式Read fixed definition.

    来源src/backend/utils/errcodes.txt

  • The fixed jsonpath executor evaluates each subscript to one numeric item, truncates it to int32, and raises 22033 for a non-single numeric result or integer-range overflow; strict mode also raises for invalid array bounds, while lax mode ignores structural out-of-bounds errors and clamps the range.

    核实方式Read the complete array-subscript execution and getArrayIndex conversion guards.

    不覆盖Source confirmation is not a natural runtime observation.

    来源src/backend/utils/adt/jsonpath_exec.c · src/backend/utils/adt/jsonpath_exec.c

  • The locked catalogue records 22033 from 12.0 without proving exact implementation introduction.

    核实方式Use catalogue boundary.

    来源src/backend/utils/errcodes.txt

同类错误代码

Class 22 数据异常 下的其他成员。