百科 / 错误代码 / Class 42 语法错误或访问规则冲突
42P20 windowing_error
窗口函数错误
ERROR 源码确认 参考 未实测
- 条件名
windowing_error- 宏名称
ERRCODE_WINDOWING_ERROR- 启用版本
- 8.4
- 状态
- 活跃
版本覆盖
速览
42P20(windowing_error)窗口定义同时约束函数调用和框架边界。
含义
固定核心在窗口函数放置或嵌套错误,以及窗口定义结构无效时使用 42P20。解析器语法拒绝不可能的框架起止组合;解析分析拒绝在不能包含窗口函数的子句中使用窗口函数,或把一个窗口函数放入另一个窗口函数;命名窗口转换则拒绝冲突的继承方式。合法框架对某一行仍可能为空,所以结果为空本身不是 42P20 信号。
诊断
先按 primary 消息分类,再改 SQL。框架消息指向 UNBOUNDED 方向或起止顺序;带 offset 的 RANGE 必须有且只有一个 ORDER BY 列,GROUPS 必须有 ORDER BY。放置消息会指出 WHERE、GROUP BY、JOIN、RETURNING 或窗口定义等子句;嵌套调用消息表示一个窗口表达式出现在另一个窗口表达式内部。命名窗口消息分别表示重复定义、覆盖所复制窗口的 PARTITION BY 或 ORDER BY,以及复制已经带框架的窗口;因此 OVER foo 与 OVER (foo) 的继承行为不同。执行器会把负的 ROWS 或 GROUPS 框架 offset 报为 SQLSTATE 22013(invalid_preceding_or_following_size),把 NULL offset 报为 22004;这些不是 42P20。
处理
把嵌套计算移到外层查询,或把窗口表达式移出消息指出的命名子句。只修复对应的框架语法,为 RANGE/GROUPS 补上所需排序,并定义一个没有冲突覆盖的命名窗口。不要因为某一当前行的框架没有行就改动本来合法的框架。如果该 ERROR 发生在显式事务中,重试前先执行 ROLLBACK,或回滚到语句前建立的保存点;自动提交模式下,失败语句返回空闲后即可提交修正查询。
消息
固定源码中的代表性消息包括:
- ERROR message:
window function calls cannot be nested - ERROR message:
frame start cannot be UNBOUNDED FOLLOWING - ERROR message:
frame starting from following row cannot end with current row - ERROR message:
frame end cannot be UNBOUNDED PRECEDING - ERROR message:
frame starting from current row cannot have preceding rows - ERROR message:
frame starting from following row cannot have preceding rows - ERROR message:
window functions are not allowed in %s - ERROR message:
window "%s" is already defined - ERROR message:
cannot override PARTITION BY clause of window "%s" - ERROR message:
cannot override ORDER BY clause of window "%s" - ERROR message:
cannot copy window "%s" because it has a frame clause - ERROR message:
cannot copy window "%s" because it has a frame clause; HINT:Omit the parentheses in this OVER clause. - ERROR message:
RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column - ERROR message:
GROUPS mode requires an ORDER BY clause
占位符由实际对象、列或参数填充。
报文模板
源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。
window function calls cannot be nested
来源:src/backend/executor/execExpr.c(lines 1155-1157) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
frame start cannot be UNBOUNDED FOLLOWING
来源:src/backend/parser/gram.y(lines 16499-16502) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
frame starting from following row cannot end with current row
来源:src/backend/parser/gram.y(lines 16504-16507) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
frame end cannot be UNBOUNDED PRECEDING
来源:src/backend/parser/gram.y(lines 16528-16531) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
frame starting from current row cannot have preceding rows
来源:src/backend/parser/gram.y(lines 16534-16537) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
frame starting from following row cannot have preceding rows
来源:src/backend/parser/gram.y(lines 16541-16544) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
window functions are not allowed in %s
来源:src/backend/parser/parse_agg.c(lines 1041-1046) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
window "%s" is already defined
来源:src/backend/parser/parse_clause.c(lines 2790-2793) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
cannot override PARTITION BY clause of window "%s"
来源:src/backend/parser/parse_clause.c(lines 2851-2855) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
cannot override ORDER BY clause of window "%s"
来源:src/backend/parser/parse_clause.c(lines 2863-2867) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
cannot copy window "%s" because it has a frame clause
来源:src/backend/parser/parse_clause.c(lines 2893-2897) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
cannot copy window "%s" because it has a frame clause
Omit the parentheses in this OVER clause.
Omit the parentheses in this OVER clause.
来源:src/backend/parser/parse_clause.c(lines 2899-2904) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column
来源:src/backend/parser/parse_clause.c(lines 2921-2924) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
GROUPS mode requires an ORDER BY clause
来源:src/backend/parser/parse_clause.c(lines 2944-2947) @ REL_18_6
适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.
版本
锁定目录显示该条件最早见于 PostgreSQL 8.4.0;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。
来源
- 上游源码 src/backend/parser/parse_clause.c 第 2851–2855 行
- 上游源码 src/backend/parser/gram.y 第 16534–16537 行
- 上游源码 src/backend/executor/execExpr.c 第 1155–1157 行
- 上游源码 src/backend/parser/gram.y 第 16541–16544 行
- 上游源码 src/backend/parser/parse_clause.c 第 2790–2793 行
- 上游源码 src/backend/parser/parse_clause.c 第 2893–2897 行
- 上游源码 src/backend/parser/gram.y 第 16499–16502 行
- 上游源码 src/backend/parser/parse_clause.c 第 2944–2947 行
- 上游源码 src/backend/parser/parse_clause.c 第 2899–2904 行
- 上游源码 src/backend/parser/parse_clause.c 第 2863–2867 行
- 上游源码 src/backend/parser/gram.y 第 16528–16531 行
- 上游源码 src/backend/parser/gram.y 第 16504–16507 行
- 上游源码 src/backend/parser/parse_clause.c 第 2921–2924 行
- 上游源码 src/backend/parser/parse_agg.c 第 1041–1046 行
- 上游源码 src/backend/executor/nodeWindowAgg.c 第 2139 行
- 上游源码 src/backend/utils/errcodes.txt 第 344 行
- 核验材料 raw/calls/REL_18_6.jsonl
证据
断言
每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。
-
42P20 is the windowing_error condition in Class 42.
-
Selected fixed 18.6 parser, parse-analysis, named-window, and executor paths reject invalid frame bounds, forbidden window placement or nesting, and illegal window inheritance. The parser also guards RANGE offset and GROUPS structural requirements.
-
The 18.6 executor assigns negative ROWS or GROUPS frame offsets to 22013 invalid_preceding_or_following_size and NULL frame offsets to 22004 null_value_not_allowed; these boundaries are separate from 42P20.
-
Locked catalogue snapshots show this condition by PostgreSQL 8.4.0; source behavior here is fixed at PostgreSQL 18.6.
同类错误代码
Class 42 语法错误或访问规则冲突 下的其他成员。
42000syntax_error_or_access_rule_violation42501insufficient_privilege42601syntax_error42602invalid_name42611invalid_column_definition42622name_too_long42701duplicate_column42702ambiguous_column42703undefined_column42704undefined_object42710duplicate_object42712duplicate_alias42723duplicate_function42725ambiguous_function42803grouping_error42804datatype_mismatch42809wrong_object_type42830invalid_foreign_key42846cannot_coerce42883undefined_function428C9generated_always42939reserved_name42P01undefined_table42P02undefined_parameter42P03duplicate_cursor42P04duplicate_database42P05duplicate_prepared_statement42P06duplicate_schema42P07duplicate_table42P08ambiguous_parameter42P09ambiguous_alias42P10invalid_column_reference42P11invalid_cursor_definition42P12invalid_database_definition42P13invalid_function_definition42P14invalid_prepared_statement_definition42P15invalid_schema_definition42P16invalid_table_definition42P17invalid_object_definition42P18indeterminate_datatype42P19invalid_recursion42P21collation_mismatch42P22indeterminate_collation