百科 / 错误代码 / Class 22 数据异常
22031 invalid_argument_for_sql_json_datetime_function
ERROR 源码确认 参考 未实测
- 条件名
invalid_argument_for_sql_json_datetime_function- 宏名称
ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION- 启用版本
- 13
- 状态
- 活跃
版本覆盖
速览
SQL/JSON datetime 方法收到无效类型、精度或格式。固定 jsonpath 执行路径报告无法识别的格式,并提示使用 datetime 模板参数。
报文
日期时间方法守卫使用以下首要文本:
| 守卫 | 首要文本和提示 |
|---|---|
| 输入项不是字符串 | jsonpath item method .%s() can only be applied to a string |
.datetime() 未识别格式 |
%s format is not recognized: "%s";HINT:Use a datetime template argument to specify the input data format. |
| 精度超出整数范围 | time precision of jsonpath item method .%s() is out of range for type integer |
| 调整后的精度无效 | time precision of jsonpath item method .%s() is invalid |
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
%s format is not recognized: "%s"
jsonpath item method .%s() can only be applied to a string
%s format is not recognized: "%s"
Use a datetime template argument to specify the input data format.
time precision of jsonpath item method .%s() is out of range for type integer
time precision of jsonpath item method .%s() is invalid
含义
固定的 executeDateTimeMethod 路径首先要求输入是标量字符串。.datetime(template) 将显式模板交给 parse_datetime:当 jspThrowErrors(cxt) 为 false 时,ErrorSaveContext 会把解析失败转成 jperError;允许抛错时不传入保存上下文,解析器可能直接抛出底层错误。没有模板的 .datetime()、.date()、.time()、.time_tz()、.timestamp() 和 .timestamp_tz() 路径会按列出的 ISO 格式循环尝试,即使在抛错执行中也会把每个候选格式的失败软保存;所有候选都失败后,最终 22031 的 RETURN_ERROR 分支才决定抛错还是返回 jperError。可选时间精度先转换为整数并检查,再进行调整。格式无法识别、转换不兼容、输入不是字符串或精度无效时使用 22031。
诊断
记录方法名、输入 JSON 项类型、日期时间文本、模板文本(如有)和精度参数。.datetime() 没有匹配格式时会提示提供模板;其他方法使用固定 ISO 候选格式,不提供该模板提示。分开判断标量类型不符、格式错误以及精度范围/调整错误。lax 控制结构上的自动包装/解包和结构错误处理,并不会普遍抑制日期时间解析或转换错误;应结合执行器的 throwErrors/RETURN_ERROR 路径,以及 jsonb_path_* 函数的 silent 参数或 SQL/JSON 的 ON ERROR 子句,判断保存的解析错误是被返回还是抛出。
处理
向方法传入字符串项;对 .datetime() 使用与日期时间文本匹配的模板,或选择与输入相符的 ISO 类型方法。保持精度符合整数和日期时间 typmod 规则。如果应用有意使用非 ERROR 的 ON ERROR 行为处理解析失败,应按应用要求保留或修正该行为;否则修正输入或模板。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的表达式。
版本
锁定目录从 13.0 起记录该条件;本页固定 SQL/JSON 日期时间源码路径为 PostgreSQL 18.6。未声称本页有自然运行观察。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 216 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 235 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 2326 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 654 行
- 上游源码 src/backend/utils/adt/jsonpath_exec.c 第 2469 行
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
22031 is invalid_argument_for_sql_json_datetime_function in SQLSTATE Class 22.
-
The fixed jsonpath datetime-method implementation first requires a string item. An explicit .datetime(template) call passes the template to parse_datetime with NULL ErrorSaveContext only when jspThrowErrors(cxt) is true; otherwise it saves the parse error and returns jperError. The no-template ISO candidate loop saves each candidate failure even on throwing execution, then the final RETURN_ERROR branch decides whether an unrecognized format throws 22031 or returns a path error. Lax controls structural auto-wrap/unwrap and structural errors; it does not generally suppress datetime parse/conversion errors. Precision, type conversion, and format guards remain 22031 paths.
-
The locked catalogue records 22031 from 13.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_value22032invalid_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_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