SQLSTATE 2201XSeverity lowLab verified

Incident brief

Negative OFFSET in a query

The OFFSET clause must skip a non-negative number of rows; an OFFSET that evaluates to a negative value raises this data exception.

What lands in your log

ERROR: OFFSET must not be negative

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

In 10 seconds

What triggers it
Run a SELECT whose OFFSET evaluates to a negative number.
Fix
Use an OFFSET of 0 or greater.
Proof
Reproduced on PostgreSQL 18.4 → A single query reproduces SQLSTATE 2201X; the planner rejects the negative OFFSET before returning any rows.

Fix

What to do right now

Application-level steps for this error.

  • Use an OFFSET of 0 or greater.
  • Clamp a computed offset with GREATEST(offset, 0), especially when it comes from pagination arithmetic like (page - 1) * size.
Fix SQL
-- OFFSET must be zero or positive.
SELECT g FROM generate_series(1,3) g OFFSET 0;

Runbook to fix this

The runbook for this incident

Full step-by-step fixes for the condition behind this error: the diagnosis, the exact SQL, and output captured in the lab.

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

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

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops