22013
Read PG 18 manual ↗invalid_preceding_or_following_size
- SQLSTATE
- 22013
- Condition name
- invalid_preceding_or_following_size
- Class
- Data Exception
- Source macro
- ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE
- Evidence
- Source path confirmed
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
At a glance
A window-frame offset is negative in a fixed ROWS or GROUPS executor path. PostgreSQL 18.6 reports either frame starting offset must not be negative or frame ending offset must not be negative with SQLSTATE 22013.
Meaning
calculate_frame_offsets evaluates the start and end expressions once for a window scan. After a non-NULL value is copied, the ROWS and GROUPS branches interpret it as an int8 offset and reject a negative value with 22013. The NULL guards use 22004 and different primary messages. RANGE frames use type-specific in_range helpers: the integer helper rejects a negative offset, numeric rejects NaN, negative infinity, or a negative value, the float helper rejects NaN or a negative value, and the timestamp-with-interval helper rejects a negative interval. These helpers use the same 22013 primary, so the frame mode and resolved offset type are part of the diagnosis.
Diagnosis
Read the frame mode, endpoint named by the primary, and the evaluated offset expression. A negative start or end in ROWS/GROUPS is this condition. In RANGE, inspect the resolved offset type: a negative integer or interval, or the rejected NaN/negative numeric and float values, reaches the same code. A NULL start or end is 22004, not 22013. This is a frame-boundary validation failure, not a generic arithmetic overflow.
Response
For a ROWS or GROUPS endpoint, provide a non-negative int8-compatible offset; for RANGE, provide a value accepted by the resolved type-specific in_range helper. Provide a non-NULL value when NULL was the actual issue. Because the cited guard raises ERROR, roll back or roll back to an existing savepoint in an explicit transaction before retrying; autocommit can retry only the corrected statement.
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 functionfor the cited type-specificRANGEoffset guards. - The cited guards add no DETAIL or HINT. NULL endpoints use SQLSTATE
22004withframe starting offset must not be nullorframe ending offset must not be null.
Versions
The locked catalogue records this condition from 11.0; fixed source coverage is PostgreSQL 18.6. The cited executor guard covers ROWS/GROUPS; the cited type-specific in_range helpers cover representative RANGE offsets.
Sources
src/backend/executor/nodeWindowAgg.c#L2144-L2210contains the start/end expression evaluation, NULL22004guards, and negativeROWS/GROUPSoffset22013guards.- Representative
RANGEhelpers use the same primary:int8.c#L400-L420rejects negative integer offsets;numeric.c#L2690-L2715rejects NaN, negative infinity, and negative numeric offsets;float.c#L1105-L1125rejects NaN or negative float offsets; andtimestamp.c#L3860-L3885rejects negative interval offsets.
Runtime verification is not_run; this source evidence is not a runtime observation. The structured evidence record retains the two endpoint variants, the generic RANGE primary, and their scope.
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
22013 is invalid_preceding_or_following_size in SQLSTATE Class 22.
Method: Read the fixed errcodes row and macro.
The window executor rejects negative ROWS/GROUPS start or end offsets with endpoint-specific 22013 primaries; NULL endpoints use 22004.
Method: Read the complete calculate_frame_offsets branches.
Limits: This source path is limited to ROWS/GROUPS.
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.
Method: Read the representative type-specific in_range guards.
Limits: The cited helpers are representative, not an exhaustive list of every range-capable type.
src.range-int8.18.6 src.range-numeric.18.6 src.range-float.18.6 src.range-timestamp.18.6
The locked catalogue records 22013 from 11.0 without proving an exact implementation introduction date.
Method: Use catalogue presence and history boundaries.
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/executor/nodeWindowAgg.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/adt/int8.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/adt/numeric.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/adt/float.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/adt/timestamp.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7
Message templates
ERROR · message.start-negative
Primary
frame starting offset must not be negative
ERROR · message.end-negative
Primary
frame ending offset must not be negative
ERROR · message.range-generic
Primary
invalid preceding or following size in window function
Reproduction & repair cases
No reproduction case is attached to this condition.
Recorded runtime evidence
No runtime observation is attached to this entry.
Version history 1
- PG 10 → 11added
Definition snapshot: english-manuals:ad8033016fb7577afd0c0ae2d99… · English manual source