select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQLSTATE / CLASS 22 · DATA EXCEPTION

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
Analysis & operational context

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 function for the cited type-specific RANGE offset guards.
  • The cited guards add no DETAIL or HINT. NULL endpoints use SQLSTATE 22004 with frame starting offset must not be null or frame 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

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.

src.errcodes.18.6

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.

src.window-executor.18.6

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.errcodes.18.6

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
  1. PG 10 → 11added

Definition snapshot: english-manuals:ad8033016fb7577afd0c0ae2d99… · English manual source