SQLSTATE 22013Severity lowLab verified

Incident brief

Negative window frame offset

A window frame's PRECEDING/FOLLOWING offset must be non-negative; a negative frame bound raises this data exception.

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Reviewed by Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What
Negative window frame offset
What triggers it
Define a window frame such as ROWS BETWEEN <n> PRECEDING with a negative <n>.
The fix
Use a non-negative frame offset.
Proof
Reproduced on PostgreSQL 18.4 → A single windowed SELECT reproduces SQLSTATE 22013; the frame offset is rejected before any aggregate is produced.

The fix

What to do right now

The immediate, application-level response to this error.

  • Use a non-negative frame offset.
  • Clamp any computed frame bound so it can never go below zero.
Fix — SQL
-- Window frame offsets must be zero or positive.
SELECT sum(g) OVER (ORDER BY g ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) FROM generate_series(1,3) g;

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Reviewed by
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed