百科 / 错误代码 / Class 22 数据异常
22013 invalid_preceding_or_following_size
ERROR 源码确认 参考 未实测
- 条件名
invalid_preceding_or_following_size- 宏名称
ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE- 启用版本
- 11
- 状态
- 活跃
版本覆盖
速览
固定的 ROWS 或 GROUPS 窗口执行路径遇到负的窗口帧偏移。PostgreSQL 18.6 以 SQLSTATE 22013 报告 frame starting offset must not be negative 或 frame ending offset must not be negative。
含义
calculate_frame_offsets 为一次窗口扫描计算起始和结束表达式。复制非 NULL 值后,ROWS 和 GROUPS 分支把它解释为 int8 偏移;负值进入 22013 guard。NULL guard 使用 22004 和不同的 primary。RANGE 帧使用按类型实现的 in_range helper:整数 helper 拒绝负偏移,numeric 拒绝 NaN、负无穷或负值,浮点 helper 拒绝 NaN 或负值,带 interval 的 timestamp helper 拒绝负 interval。这些 helper 使用同一个 22013 primary,因此帧模式和解析后的偏移类型都是诊断条件。
诊断
阅读帧模式、primary 指出的端点和偏移表达式的实际值。在 ROWS/GROUPS 中,起点或终点为负就是本码。在 RANGE 中,应按解析后的偏移类型判断:负整数或 interval,以及被拒绝的 NaN/负 numeric 或浮点值,都进入同一代码。起点或终点为 NULL 属于 22004,不是 22013。这是帧边界校验失败,不是一般算术溢出。
处理
对于 ROWS 或 GROUPS 端点,提供非负且可转为 int8 的偏移;对于 RANGE,提供符合解析后类型 in_range helper 要求的值。如果实际问题是 NULL,则提供非 NULL 值。引用的 guard 抛出 ERROR,因此显式事务需先 ROLLBACK 或回到已有保存点后再重试,自动提交只重试修正后的语句。
报文
- Primary,
ERROR:frame starting offset must not be negative。 - Primary,
ERROR:frame ending offset must not be negative。 - Primary,
ERROR:invalid preceding or following size in window function,用于引用的按类型RANGE偏移 guard。 - 引用的 guard 没有附加 DETAIL 或 HINT。NULL 端点使用 SQLSTATE
22004,primary 分别为frame starting offset must not be null和frame ending offset must not be null。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
frame starting offset must not be negative
frame ending offset must not be negative
invalid preceding or following size in window function
来源:src/backend/utils/adt/int8.c @ REL_18_6 · src/backend/utils/adt/numeric.c @ REL_18_6 · src/backend/utils/adt/float.c @ REL_18_6 · src/backend/utils/adt/timestamp.c @ REL_18_6
版本
锁定目录从 11.0 起记录该条件;固定源码覆盖 PostgreSQL 18.6。引用的执行器 guard 覆盖 ROWS/GROUPS;引用的按类型 in_range helper 也覆盖了代表性的 RANGE 偏移。
来源
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
22013 is invalid_preceding_or_following_size in SQLSTATE Class 22.
-
The window executor rejects negative ROWS/GROUPS start or end offsets with endpoint-specific 22013 primaries; NULL endpoints use 22004.
-
Representative RANGE in_range helpers reject negative integer or interval offsets and reject the specified NaN/negative numeric and float offsets with the generic 22013 primary.
-
The locked catalogue records 22013 from 11.0 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_value22011substring_error22012division_by_zero22014invalid_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