选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 错误代码 / Class 22 数据异常

22013 invalid_preceding_or_following_size

ERROR 源码确认 参考 未实测

类别
Class 22 数据异常
严重等级
ERROR
条件名
invalid_preceding_or_following_size
宏名称
ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE
启用版本
11
状态
活跃

版本覆盖

速览

固定的 ROWSGROUPS 窗口执行路径遇到负的窗口帧偏移。PostgreSQL 18.6 以 SQLSTATE 22013 报告 frame starting offset must not be negativeframe ending offset must not be negative

含义

calculate_frame_offsets 为一次窗口扫描计算起始和结束表达式。复制非 NULL 值后,ROWSGROUPS 分支把它解释为 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。这是帧边界校验失败,不是一般算术溢出。

处理

对于 ROWSGROUPS 端点,提供非负且可转为 int8 的偏移;对于 RANGE,提供符合解析后类型 in_range helper 要求的值。如果实际问题是 NULL,则提供非 NULL 值。引用的 guard 抛出 ERROR,因此显式事务需先 ROLLBACK 或回到已有保存点后再重试,自动提交只重试修正后的语句。

报文

  • Primary,ERRORframe starting offset must not be negative
  • Primary,ERRORframe ending offset must not be negative
  • Primary,ERRORinvalid preceding or following size in window function,用于引用的按类型 RANGE 偏移 guard。
  • 引用的 guard 没有附加 DETAIL 或 HINT。NULL 端点使用 SQLSTATE 22004,primary 分别为 frame starting offset must not be nullframe ending offset must not be null

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 frame starting offset must not be negative

来源:src/backend/executor/nodeWindowAgg.c @ REL_18_6

主消息 frame ending offset must not be negative

来源:src/backend/executor/nodeWindowAgg.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.

    核实方式Read the fixed errcodes row and macro.

    来源src/backend/utils/errcodes.txt

  • The window executor rejects negative ROWS/GROUPS start or end offsets with endpoint-specific 22013 primaries; NULL endpoints use 22004.

    核实方式Read the complete calculate_frame_offsets branches.

    不覆盖This source path is limited to ROWS/GROUPS.

    来源src/backend/executor/nodeWindowAgg.c

  • 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.

    核实方式Read the representative type-specific in_range guards.

    不覆盖The cited helpers are representative, not an exhaustive list of every range-capable type.

    来源src/backend/utils/adt/int8.c · src/backend/utils/adt/numeric.c · src/backend/utils/adt/float.c · src/backend/utils/adt/timestamp.c

  • The locked catalogue records 22013 from 11.0 without proving an exact implementation introduction date.

    核实方式Use catalogue presence and history boundaries.

    来源src/backend/utils/errcodes.txt

同类错误代码

Class 22 数据异常 下的其他成员。