百科 / 错误代码 / Class 22 数据异常
22038 singleton_sql_json_item_required
ERROR 源码确认 参考 未实测
- 条件名
singleton_sql_json_item_required- 宏名称
ERRCODE_SINGLETON_SQL_JSON_ITEM_REQUIRED- 启用版本
- 12
- 状态
- 活跃
版本覆盖
速览
SQL/JSON 路径操作要求一个特定类型的单一结果,却收到了不同的基数或类型。固定路径覆盖单一布尔结果,以及 jsonpath 二元算术的左右两个数值操作数;SQL 函数和 @@ 操作符的 silent 默认行为不同。
报文
代表性首要报文如下:
| 触发条件 | 首要报文 |
|---|---|
抛错模式下 jsonb_path_match 的结果不是单一布尔项 |
single boolean result is expected |
| 二元算术左操作数不是一个数值项 | left operand of jsonpath operator %s is not a single numeric value |
| 二元算术右操作数不是一个数值项 | right operand of jsonpath operator %s is not a single numeric value |
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
single boolean result is expected
left operand of jsonpath operator %s is not a single numeric value
right operand of jsonpath operator %s is not a single numeric value
含义
jsonb_path_match_internal 把恰好两个 C 参数识别为 @@ 操作符路径:jsonb_path_match_opr 保持 silent=true,所以结果不是单一布尔项时返回 NULL。SQL 函数声明为 jsonb_path_match(target, path, vars DEFAULT '{}', silent DEFAULT false);即使 SQL 调用只写两个参数,两个默认参数也会补齐,因此它是非 silent 的,除非调用者显式传入 silent=true,否则可能报告 22038。四参数调用遵循实际传入的 silent 值。单个 JSON null 会返回 SQL NULL。二元算术则分别计算左右操作数序列,两边都必须恰好包含一个数值项。共享执行器在 lax 模式下可能先解包数组,再进行单项检查。
诊断
先确认语法使用的是 @@ 操作符还是 jsonb_path_match 函数,并检查实际参数及默认参数展开,之后再解释 NULL 结果。路径产生多个值、match 结果不是布尔值,或左右项不是数值,都属于这个单项/类型边界。将其与 JSON_QUERY/JSON_VALUE 基数错误 22034、标量类型约束 2203F,以及数值项方法转换错误 22036 区分开。
处理
收窄路径或明确选取一个项。二元算术应确保左右操作数各自解析为一个数值项;如果确实需要抑制错误可使用 @@,如果希望不匹配仍报告 ERROR 则调用 jsonb_path_match(..., false);只有业务确实要返回 NULL 时才传入 silent=true。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的动作。
版本
锁定目录从 12.0 起记录该条件;固定的 match 和二元算术路径来自 PostgreSQL 18.6。本页未声称有自然运行观察。
来源
- 上游源码 src/include/catalog/pg_operator.dat 第 3262 行
- 上游源码 src/include/catalog/pg_proc.dat 第 10520 行
- 上游源码 src/include/catalog/pg_proc.dat 第 10547 行
- 上游源码 src/backend/catalog/system_functions.sql 第 539 行
- 上游源码 src/backend/utils/errcodes.txt 第 223 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 2087 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 235 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 654 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 453 行
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
22038 is singleton_sql_json_item_required in SQLSTATE Class 22.
-
The fixed jsonb_path_match_internal path treats exactly two C arguments as the @@ operator call: jsonb_path_match_opr leaves silent=true, so a non-singleton or non-boolean result is suppressed to NULL. The SQL function jsonb_path_match has vars DEFAULT '{}' and silent DEFAULT false; even a call written with two SQL arguments is expanded with both defaults, so it is non-silent unless silent=true is explicitly supplied. Binary jsonpath arithmetic independently requires each operand sequence to contain exactly one numeric item; lax unwrapping is performed by the shared evaluator.
-
The locked catalogue records 22038 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_subscript22034more_than_one_sql_json_item22035no_sql_json_item22036non_numeric_sql_json_item22037non_unique_keys_in_a_json_object22039sql_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