22013 — invalid_preceding_or_following_size
窗口帧的 PRECEDING/FOLLOWING 偏移为负。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Data Exception
- condition name
- invalid_preceding_or_following_size
- lang
- en
- sqlstate
- 22013
版本定义 PG 18
速览 {#at-a-glance}
固定的 ROWS 或 GROUPS 窗口执行路径遇到负的窗口帧偏移。PostgreSQL 18.6 以 SQLSTATE 22013 报告 frame starting offset must not be negative 或 frame ending offset must not be negative。
含义 {#meaning}
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,因此帧模式和解析后的偏移类型都是诊断条件。
诊断 {#diagnosis}
阅读帧模式、primary 指出的端点和偏移表达式的实际值。在 ROWS/GROUPS 中,起点或终点为负就是本码。在 RANGE 中,应按解析后的偏移类型判断:负整数或 interval,以及被拒绝的 NaN/负 numeric 或浮点值,都进入同一代码。起点或终点为 NULL 属于 22004,不是 22013。这是帧边界校验失败,不是一般算术溢出。
处理 {#response}
对于 ROWS 或 GROUPS 端点,提供非负且可转为 int8 的偏移;对于 RANGE,提供符合解析后类型 in_range helper 要求的值。如果实际问题是 NULL,则提供非 NULL 值。引用的 guard 抛出 ERROR,因此显式事务需先 ROLLBACK 或回到已有保存点后再重试,自动提交只重试修正后的语句。
报文 {#messages}
- 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。
版本 {#versions}
锁定目录从 11.0 起记录该条件;固定源码覆盖 PostgreSQL 18.6。引用的执行器 guard 覆盖 ROWS/GROUPS;引用的按类型 in_range helper 也覆盖了代表性的 RANGE 偏移。
相关 {#related}
来源 {#sources}
src/backend/executor/nodeWindowAgg.c#L2144-L2210包含起始/结束表达式计算、NULL 的22004guard,以及负ROWS/GROUPS偏移的22013guard。- 代表性的
RANGEhelper 使用同一个 primary:int8.c#L400-L420拒绝负整数偏移;numeric.c#L2690-L2715拒绝 NaN、负无穷和负 numeric 偏移;float.c#L1105-L1125拒绝 NaN 或负浮点偏移;timestamp.c#L3860-L3885拒绝负 interval 偏移。
运行核验为 not_run;上述源码证据不是运行观察。结构化证据记录保留两个端点变体、RANGE 通用 primary 及其范围。
比较版本
SQLSTATE 证据与已记录的运行版本
claims · identity
{
"claim_id": "identity",
"limits": "",
"method": "Read the fixed errcodes row and macro.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "22013 is invalid_preceding_or_following_size in SQLSTATE Class 22."
}claims · resolved-rows-groups-path
{
"claim_id": "resolved-rows-groups-path",
"limits": "This source path is limited to ROWS/GROUPS.",
"method": "Read the complete calculate_frame_offsets branches.",
"position": 1,
"runtime": [],
"sources": [
"src.window-executor.18.6"
],
"statement": "The window executor rejects negative ROWS/GROUPS start or end offsets with endpoint-specific 22013 primaries; NULL endpoints use 22004."
}claims · resolved-range-path
{
"claim_id": "resolved-range-path",
"limits": "The cited helpers are representative, not an exhaustive list of every range-capable type.",
"method": "Read the representative type-specific in_range guards.",
"position": 2,
"runtime": [],
"sources": [
"src.range-int8.18.6",
"src.range-numeric.18.6",
"src.range-float.18.6",
"src.range-timestamp.18.6"
],
"statement": "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."
}claims · history
{
"claim_id": "history",
"limits": "",
"method": "Use catalogue presence and history boundaries.",
"position": 3,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "The locked catalogue records 22013 from 11.0 without proving an exact implementation introduction date."
}messages · message.start-negative
{
"limits": "",
"message_id": "message.start-negative",
"path": "",
"position": 0,
"raw": {
"id": "message.start-negative",
"primary_template": "frame starting offset must not be negative",
"severity_source": "ERROR",
"sources": [
"src.window-executor.18.6"
],
"sqlstate": "22013"
},
"severity": "ERROR",
"sources": [
"src.window-executor.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "frame starting offset must not be negative",
"position": 0,
"role": "",
"template": "frame starting offset must not be negative"
}
]
}messages · message.end-negative
{
"limits": "",
"message_id": "message.end-negative",
"path": "",
"position": 1,
"raw": {
"id": "message.end-negative",
"primary_template": "frame ending offset must not be negative",
"severity_source": "ERROR",
"sources": [
"src.window-executor.18.6"
],
"sqlstate": "22013"
},
"severity": "ERROR",
"sources": [
"src.window-executor.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "frame ending offset must not be negative",
"position": 0,
"role": "",
"template": "frame ending offset must not be negative"
}
]
}messages · message.range-generic
{
"limits": "",
"message_id": "message.range-generic",
"path": "",
"position": 2,
"raw": {
"id": "message.range-generic",
"primary_template": "invalid preceding or following size in window function",
"severity_source": "ERROR",
"sources": [
"src.range-int8.18.6",
"src.range-numeric.18.6",
"src.range-float.18.6",
"src.range-timestamp.18.6"
],
"sqlstate": "22013"
},
"severity": "ERROR",
"sources": [
"src.range-int8.18.6",
"src.range-numeric.18.6",
"src.range-float.18.6",
"src.range-timestamp.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "invalid preceding or following size in window function",
"position": 0,
"role": "",
"template": "invalid preceding or following size in window function"
}
]
}sources · src.errcodes.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L183"
}sources · src.window-executor.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/executor/nodeWindowAgg.c",
"position": 1,
"sha256": "c365e6750bc77a89562254903d099c3e5914e001d3aae418322ccffc1d535d17",
"source_id": "src.window-executor.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeWindowAgg.c#L2144-2210"
}sources · src.range-int8.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/int8.c",
"position": 2,
"sha256": "da4d3688c0b037346f25419ea31020af9fec54021f182370234dcbf70b748f36",
"source_id": "src.range-int8.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/int8.c#L400-420"
}sources · src.range-numeric.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/numeric.c",
"position": 3,
"sha256": "6cde7cd60b3330b83be35d1f014045f5fb5fe737f3c5db4c8ed4080b99f2b666",
"source_id": "src.range-numeric.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/numeric.c#L2690-2715"
}sources · src.range-float.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/float.c",
"position": 4,
"sha256": "58914ae93c06c281e581a4bb2dcf2280e4ae1619f3ceb8f801f50beca87eecd8",
"source_id": "src.range-float.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/float.c#L1105-1125"
}sources · src.range-timestamp.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/timestamp.c",
"position": 5,
"sha256": "2614ccd2182fa904b4cac9bef43039e90a1af578d2d1c6803d49a07420d168f2",
"source_id": "src.range-timestamp.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/timestamp.c#L3860-3885"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:31787642ffd2219efb1ef4b28cca420c766afabbfb87f486cc29d6b66092efe4
正文语言: zh-Hans · english-manuals:31787642ffd2219efb1ef4b28cca420c766afabbfb87f486cc29d6b66092efe4