百科 / 错误代码 / Class 22 数据异常
2203F sql_json_scalar_required
ERROR 源码确认 参考 未实测
- 条件名
sql_json_scalar_required- 宏名称
ERRCODE_SQL_JSON_SCALAR_REQUIRED- 启用版本
- 12
- 状态
- 活跃
版本覆盖
速览
JSON_VALUE 收到一个项,但该项不是标量。多个项会在更早的 22034 基数分支处理;空结果则由空结果/ON EMPTY 路径处理。
报文
固定的 JSON_VALUE 标量检查条件使用以下首要报文形式:
| 上下文 | 首要报文 |
|---|---|
| JSON_VALUE 映射到命名列 | JSON path expression for column "%s" must return single scalar item |
| 独立 JSON_VALUE | JSON path expression in JSON_VALUE must return single scalar item |
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
JSON path expression for column "%s" must return single scalar item
JSON path expression in JSON_VALUE must return single scalar item
含义
JsonPathValue 先执行路径并标记空结果。多个项属于独立的 22034 基数分支。恰好一个项时,它会在必要时解开标量 JSON 容器,然后要求结果是 JSON 标量;对象或数组会进入 2203F。如果调用方为 ON ERROR 提供了错误指针,函数会设置错误标志并返回 NULL,而不是直接抛错。普通 ERROR 路径会报告上面按列名区分或不带列名的首要报文。
诊断
检查 JSON_VALUE 路径结果的项数和选中项类型。空结果、多个项、单个非标量项分别属于不同分支,处理方式也不同。修改源 JSON 前先检查列映射以及 ON EMPTY/ON ERROR 子句,并把 JSON_QUERY 的包装语义与 JSON_VALUE 的标量要求区分开。
处理
让路径解析为一个标量;如果业务确实需要对象或数组,改用合适的 SQL/JSON 操作;对预期缺失则配置文档规定的空值/错误处理。不要为了让集合看起来像标量而给 JSON_VALUE 添加包装。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的动作。
版本
锁定目录从 12.0 起记录该条件;固定的 JSON_VALUE 基数和标量检查来自 PostgreSQL 18.6。本页未声称有自然运行观察。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 230 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 3991 行
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
2203F is sql_json_scalar_required in SQLSTATE Class 22.
-
The fixed JSON_VALUE executor marks an empty result before cardinality checks, reports 22034 for more than one item, and then requires the single remaining item to be a JSON scalar; a non-scalar item reaches 2203F. When an error pointer is supplied for ON ERROR handling, the function sets the error flag and returns NULL instead of throwing; the ordinary path emits the column-aware or column-less primary.
-
The locked catalogue records 2203F 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_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_members2203Gsql_json_item_cannot_be_cast_to_target_type22P01floating_point_exception22P02invalid_text_representation22P03invalid_binary_representation22P04bad_copy_file_format22P05untranslatable_character22P06nonstandard_use_of_escape_character