百科 / 错误代码 / Class 22 数据异常
22034 more_than_one_sql_json_item
ERROR 源码确认 参考 未实测
- 条件名
more_than_one_sql_json_item- 宏名称
ERRCODE_MORE_THAN_ONE_SQL_JSON_ITEM- 启用版本
- 12
- 状态
- 活跃
版本覆盖
速览
操作要求单个 SQL/JSON 项却得到多个项。固定 JSON_QUERY/JSON_VALUE 路径报告必须是单项或单标量,并可能提示使用 WITH WRAPPER。
报文
无 wrapper 的基数守卫使用以下首要文本:
| 操作 | 首要文本和提示 |
|---|---|
无 wrapper 的 JSON_QUERY 列 |
JSON path expression for column "%s" must return single item when no wrapper is requested;HINT:Use the WITH WRAPPER clause to wrap SQL/JSON items into an array. |
没有列名的 JSON_QUERY |
JSON path expression in JSON_QUERY must return single item when no wrapper is requested;HINT:Use the WITH WRAPPER clause to wrap SQL/JSON items into an array. |
JSON_VALUE 返回多个项 |
JSON path expression in JSON_VALUE must return single scalar item |
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
JSON path expression for column "%s" must return single item when no wrapper is requested
Use the WITH WRAPPER clause to wrap SQL/JSON items into an array.
JSON path expression in JSON_QUERY must return single item when no wrapper is requested
Use the WITH WRAPPER clause to wrap SQL/JSON items into an array.
JSON path expression in JSON_VALUE must return single scalar item
含义
固定的 JSON_QUERY 路径会收集完整 SQL/JSON 结果列表,并在应用 wrapper 模式前统计数量。没有 wrapper 时返回多个项会报告 22034;无条件或条件 WITH WRAPPER 会按模式把序列变成数组。JSON_VALUE 返回多个项时也使用本码,因为它要求单个标量。恰好一个非标量项属于独立的 2203F,零项则设置 empty 标志并交给 ON EMPTY 处理。lax 的自动展开可能改变结果基数;silent 或非 ERROR 的 ON ERROR 行为可能在基数守卫之前抑制求值错误。
诊断
记录操作类型(JSON_QUERY 或 JSON_VALUE)、wrapper 子句、列名以及 path 产生的项数。JSON_QUERY 只有在确实需要数组结果时才使用 WITH WRAPPER;JSON_VALUE 应将 path 缩减为单个标量。区分多个项(22034)、单个非标量项(2203F)和由 ON EMPTY/22035 处理的无项结果。检查 strict/lax 和 silent 设置,因为它们会影响守卫看到的结果序列。
处理
修改 path 或过滤条件,使其返回所需的单个项;如果消费方需要数组,则加入文档规定的 wrapper。对 JSON_VALUE 还要确保该项是标量。如果操作使用 ON ERROR 行为,应使回退值符合预期基数,不要把 NULL 误当成 path 返回了单个项。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的表达式。
版本
锁定目录从 12.0 起记录该条件;本页固定 SQL/JSON 基数源码路径为 PostgreSQL 18.6。未声称本页有自然运行观察。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 219 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 3880 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 3966 行
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
22034 is more_than_one_sql_json_item in SQLSTATE Class 22.
-
The fixed JSON_QUERY path collects the complete SQL/JSON result list, uses the wrapper mode to permit multiple items, and emits 22034 only when more than one item remains without a wrapper; JSON_VALUE uses the same code for more than one item, while a single non-scalar is the separate 2203F condition.
-
The locked catalogue records 22034 from 12.0 without proving exact implementation introduction.
同类错误代码
Class 22 数据异常 下的其他成员。
22000data_exception22001string_data_right_truncation22002null_value_no_indicator_parameter22003numeric_value_out_of_range22004null_value_not_allowed22005error_in_assignment22007invalid_datetime_format22008datetime_field_overflow22009invalid_time_zone_displacement_value2200Bescape_character_conflict2200Cinvalid_use_of_escape_character2200Dinvalid_escape_octet2200Fzero_length_character_string2200Gmost_specific_type_mismatch2200Hsequence_generator_limit_exceeded2200Lnot_an_xml_document2200Minvalid_xml_document2200Ninvalid_xml_content2200Sinvalid_xml_comment2200Tinvalid_xml_processing_instruction22010invalid_indicator_parameter_value22011substring_error22012division_by_zero22013invalid_preceding_or_following_size22014invalid_argument_for_ntile_function22015interval_field_overflow22016invalid_argument_for_nth_value_function22018invalid_character_value_for_cast22019invalid_escape_character2201Binvalid_regular_expression2201Einvalid_argument_for_logarithm2201Finvalid_argument_for_power_function2201Ginvalid_argument_for_width_bucket_function2201Winvalid_row_count_in_limit_clause2201Xinvalid_row_count_in_result_offset_clause22021character_not_in_repertoire22022indicator_overflow22023invalid_parameter_value22024unterminated_c_string22025invalid_escape_sequence22026string_data_length_mismatch22027trim_error2202Earray_subscript_error2202Ginvalid_tablesample_repeat2202Hinvalid_tablesample_argument22030duplicate_json_object_key_value22031invalid_argument_for_sql_json_datetime_function22032invalid_json_text22033invalid_sql_json_subscript22035no_sql_json_item22036non_numeric_sql_json_item22037non_unique_keys_in_a_json_object22038singleton_sql_json_item_required22039sql_json_array_not_found2203Asql_json_member_not_found2203Bsql_json_number_not_found2203Csql_json_object_not_found2203Dtoo_many_json_array_elements2203Etoo_many_json_object_members2203Fsql_json_scalar_required2203Gsql_json_item_cannot_be_cast_to_target_type22P01floating_point_exception22P02invalid_text_representation22P03invalid_binary_representation22P04bad_copy_file_format22P05untranslatable_character22P06nonstandard_use_of_escape_character