百科 / 错误代码 / Class 22 数据异常
22011 substring_error
ERROR 源码确认 参考 未实测
- 条件名
substring_error- 宏名称
ERRCODE_SUBSTRING_ERROR- 启用版本
- 7.4
- 状态
- 活跃
版本覆盖
速览
文本子字符串路径收到无效的显式长度。固定的 PostgreSQL 18.6 代码中,text_substring 以 SQLSTATE 22011 报告 negative substring length not allowed。
含义
三参数文本子字符串包装器把显式长度传给 text_substring;负长度会进入 ERRCODE_SUBSTRING_ERROR guard。无长度包装器则传入带有 length_not_specified 的哨兵值,返回剩余文本,不会进入负长度 guard。OVERLAY 的起点不为正时也复用这个报错。本证据针对文本路径;bytea、位串和基于模式的 substring 有各自的消费者,应以完整诊断识别。
诊断
修改前先确认解析出的操作和数据类型。对文本路径,要区分显式负长度与零或负起点:源码把有效起点调整为 1,并按 SQL 规则调整长度。起点超过末尾会返回空串。起点加长度的 32 位计算溢出时,子串延伸到末尾,并不报本码。OVERLAY 的非正起点使用同一 primary,而起点加长度溢出则使用 22003。
处理
传入非负的显式文本长度;若意图是取到末尾,则省略长度。保留预期的一基起点语义,并在修复前确认实际数据类型。该路径抛出 ERROR;显式事务需先 ROLLBACK 或回到已有保存点后再重试,自动提交只重试修正后的语句。
报文
- Primary,
ERROR:显式文本子字符串 guard 和非正OVERLAY起点 guard 都是negative substring length not allowed;这些路径没有固定 DETAIL 或 HINT。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
negative substring length not allowed
来源:src/backend/utils/adt/varlena.c @ REL_18_6
适用范围:Explicit negative text length.
negative substring length not allowed
来源:src/backend/utils/adt/varlena.c @ REL_18_6
适用范围:Non-positive OVERLAY start; this is not the OVERLAY overflow branch.
版本
锁定目录从 7.4 起记录该条件;固定源码覆盖 PostgreSQL 18.6。引用的 guard 是当前版本的文本和 OVERLAY 路径,不推广到所有 substring 实现。
来源
- 上游源码 src/backend/utils/errcodes.txt 第 180 行
- 上游源码 src/backend/utils/adt/varlena.c
- 上游源码 src/backend/utils/adt/varlena.c
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
22011 is substring_error in SQLSTATE Class 22.
-
The fixed text_substring path raises 22011 only for an explicit negative length; the omitted-length sentinel returns the remainder and the start/end calculations cover empty and overflow cases.
-
The fixed OVERLAY path reuses the 22011 primary for a non-positive start, while an overflowing start-plus-length uses 22003.
-
The locked catalogue records 22011 from 7.4 without proving an exact implementation introduction date.
同类错误代码
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_value22012division_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_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