42P20
Read PG 18 manual ↗windowing_error
- SQLSTATE
- 42P20
- Condition name
- windowing_error
- Class
- Syntax Error or Access Rule Violation
- Source macro
- ERRCODE_WINDOWING_ERROR
- Evidence
- Source path confirmed
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
At a glance
42P20 (windowing_error) Window definitions constrain both calls and frame boundaries.
Meaning
The fixed core uses 42P20 for window-function placement or nesting errors and for invalid window-definition structure. Parser grammar rejects impossible frame start/end combinations; parse analysis rejects a window function in a clause that cannot contain it or another window function; named-window transformation rejects conflicting inheritance. A legal frame can still be empty for a particular row, so an empty result is not by itself a 42P20 signal.
Diagnosis
Classify the primary message before changing SQL. A frame message points to UNBOUNDED direction or start/end ordering; RANGE with an offset requires exactly one ORDER BY column and GROUPS requires an ORDER BY clause. A placement message names a clause such as WHERE, GROUP BY, JOIN, RETURNING, or a window definition, while the nested-call message means a window expression appears inside another window expression. Named-window messages distinguish duplicate definitions, attempts to override copied PARTITION BY or ORDER BY, and copying a window that already has a frame; OVER foo and OVER (foo) therefore have different inheritance behavior. The executor separately reports negative ROWS or GROUPS frame offsets as SQLSTATE 22013 (invalid_preceding_or_following_size), and null offsets as 22004; those are not 42P20.
Response
Move a nested calculation to an outer query level, or move the window expression out of the named clause identified by the message. Repair only the relevant frame grammar, add the required ordering for RANGE/GROUPS, and define one named window without conflicting overrides. Do not change a valid frame merely because it produces no rows for one current row. If this ERROR occurs inside an explicit transaction, issue ROLLBACK or ROLLBACK TO a savepoint created before the statement before retrying; autocommit can submit the corrected query after the failed statement returns to idle.
Messages
Representative fixed-source messages include:
- 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
Placeholders are filled by the actual object, column, or parameter.
Versions
The locked catalogue shows this condition by PostgreSQL 8.4.0; behavior here is fixed to PostgreSQL 18.6 source. Catalogue presence is a range boundary, not proof that every message or feature began in that release.
Sources
Source messages, line anchors, and evidence limits are recorded in authored evidence.
src/backend/executor/execExpr.c:1155-1157(fixed source)src/backend/parser/gram.y:16499-16544(fixed source)src/backend/parser/parse_agg.c:1041-1046(fixed source)src/backend/parser/parse_clause.c:2790-2947(fixed source)src/backend/executor/nodeWindowAgg.c:2139-2210(fixed source)
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
42P20 is the windowing_error condition in Class 42.
Method: Read fixed REL_18_6 errcodes.txt and locked facts.
Limits: Identity does not enumerate all source branches or client failures.
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.
Method: Read complete fixed-source contexts around the selected report groups and the frame-offset executor guard.
Limits: Representative confirmed core paths only; not exhaustive historical or extension coverage. A legal frame can still evaluate to no rows for a particular row.
src.call.42P20.17809e6b7f525d4ed41961ed src.call.42P20.5670c88a2f3e05b693257e49 src.call.42P20.ed2f8bce483ee7cc9c9ff7e0 src.call.42P20.af44057d6b02e78ceb659ea3 src.call.42P20.05acd1c626dd243023930f4b src.call.42P20.2b557a2b5c702ff1eeb57eaa src.call.42P20.fde5045d9190c4d041b74444 src.call.42P20.4d72e034c551705933ff1342 src.call.42P20.0221c1569253594c6c3f8117 src.call.42P20.ae80656ed795057fab150a08 src.call.42P20.51b9fa13c98768648a42bec3 src.call.42P20.879f1f1e1a0b390154b2b059 src.call.42P20.faf4767dd0e2b75c0c2f5763 src.call.42P20.745a6ce52598aa006a4c0b9d src.context.42P20.nodeWindowAgg
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.
Method: Read nodeWindowAgg.c calculate_frame_offsets and the fixed error-code catalogue.
Limits: Boundary only; no natural runtime execution is claimed.
Locked catalogue snapshots show this condition by PostgreSQL 8.4.0; source behavior here is fixed at PostgreSQL 18.6.
Method: Read locked catalogue facts and definition snapshot.
Limits: First observed release is a lower bound, not precise behavioral introduction.
- src/backend/utils/errcodes.txt · REL_18_6 · line 344
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/executor/execExpr.c · REL_18_6 · lines 1155-1157
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/gram.y · REL_18_6 · lines 16499-16502
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/gram.y · REL_18_6 · lines 16504-16507
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/gram.y · REL_18_6 · lines 16528-16531
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/gram.y · REL_18_6 · lines 16534-16537
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/gram.y · REL_18_6 · lines 16541-16544
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_agg.c · REL_18_6 · lines 1041-1046
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_clause.c · REL_18_6 · lines 2790-2793
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_clause.c · REL_18_6 · lines 2851-2855
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_clause.c · REL_18_6 · lines 2863-2867
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_clause.c · REL_18_6 · lines 2893-2897
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_clause.c · REL_18_6 · lines 2899-2904
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_clause.c · REL_18_6 · lines 2921-2924
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_clause.c · REL_18_6 · lines 2944-2947
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/executor/nodeWindowAgg.c · REL_18_6 · lines 2139-2210
724edf9bde9d356724ad384a2e196edc3c9f80f7 raw/calls/REL_18_6.jsonl· ·
Message templates
ERROR · message.variant-1
Primary
window function calls cannot be nested
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-2
Primary
frame start cannot be UNBOUNDED FOLLOWING
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-3
Primary
frame starting from following row cannot end with current row
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-4
Primary
frame end cannot be UNBOUNDED PRECEDING
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-5
Primary
frame starting from current row cannot have preceding rows
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-6
Primary
frame starting from following row cannot have preceding rows
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-7
Primary
window functions are not allowed in %s
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-8
Primary
window "%s" is already defined
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-9
Primary
cannot override PARTITION BY clause of window "%s"
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-10
Primary
cannot override ORDER BY clause of window "%s"
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-11
Primary
cannot copy window "%s" because it has a frame clause
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-12
Primary
cannot copy window "%s" because it has a frame clause
Hint
Omit the parentheses in this OVER clause.
Primary
Omit the parentheses in this OVER clause.
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-13
Primary
RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
ERROR · message.variant-14
Primary
GROUPS mode requires an ORDER BY clause
Placeholders remain dynamic source fields; no concrete runtime value is claimed.
Reproduction & repair cases
No reproduction case is attached to this condition.
Recorded runtime evidence
No runtime observation is attached to this entry.
Definition snapshot: english-manuals:eb1e13135c938cb4f3ffeba89a6… · English manual source