↑↓ select↵ open⌫ change scopeOpen full search

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

Wiki / SQLSTATE

2201X — invalid_row_count_in_result_offset_clause

An OFFSET expression is negative after evaluation. The fixed executor path reports OFFSET must not be negative.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Data Exception
condition name
invalid_row_count_in_result_offset_clause
lang
en
sqlstate
2201X

Definition PG 18

2201X

At a glance {#at-a-glance}

An OFFSET expression is negative after evaluation. The fixed executor path reports OFFSET must not be negative.

Meaning {#meaning}

During LIMIT-node recomputation, a NULL OFFSET is interpreted as zero (no offset), zero is valid, and only a negative evaluated offset reaches 2201X. This is the OFFSET-specific sibling of 2201W; LIMIT count rules must be diagnosed from their own SQLSTATE.

Diagnosis {#diagnosis}

Inspect the evaluated OFFSET expression after parameter substitution and type resolution. Distinguish NULL/no offset and zero from a negative value, and do not relabel a LIMIT or FETCH row-count failure as 2201X.

Response {#response}

Supply a non-negative OFFSET, or NULL when the intended result is no offset. If the ERROR occurred in an explicit transaction, roll back or roll back to the existing savepoint before retrying; autocommit can retry the corrected statement.

Versions {#versions}

The locked catalogue records this condition from 8.4.0; the fixed source path here is PostgreSQL 18.6. No natural runtime observation is claimed for this page.

Related {#related}

2201W, 22003

Sources {#sources}

The executor’s NULL-to-zero and negative guard are in src/backend/executor/nodeLimit.c#L356-375. The structured evidence record retains the exact primary template and source boundary; no natural runtime was run.

Compare versions

SQLSTATE evidence and recorded runtime versions

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read the fixed errcodes row and macro.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "2201X is invalid_row_count_in_result_offset_clause in SQLSTATE Class 22"
}
claims · resolved-path
{
  "claim_id": "resolved-path",
  "limits": "Source confirmation is not a natural runtime observation.",
  "method": "Read complete source contexts for the representative guards.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.nodeLimit.offset"
  ],
  "statement": "Fixed PostgreSQL 18.6 executor recomputation maps NULL OFFSET to zero and emits 2201X only for a negative evaluated offset."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue presence and history boundaries.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 2201X from 8.4.0 without proving an exact implementation introduction date."
}
messages · message.offset-negative
{
  "limits": "",
  "message_id": "message.offset-negative",
  "path": "",
  "position": 0,
  "raw": {
    "id": "message.offset-negative",
    "primary_template": "OFFSET must not be negative",
    "severity_source": "ERROR",
    "sources": [
      "src.nodeLimit.offset"
    ],
    "sqlstate": "2201X"
  },
  "severity": "ERROR",
  "sources": [
    "src.nodeLimit.offset"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "OFFSET must not be negative",
      "position": 0,
      "role": "",
      "template": "OFFSET must not be negative"
    }
  ]
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L189"
}
sources · src.nodeLimit.offset
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/executor/nodeLimit.c",
  "position": 1,
  "sha256": "f4c202d7182d66c6bef222fa50439831691dd99bfa5fd6b4de7f9142635dc305",
  "source_id": "src.nodeLimit.offset",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeLimit.c#L356"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:a9a202940b4444e90645d6e2785180ffe3ab0a7284793473e2d8009cad2c989d

Text language: en · english-manuals:a9a202940b4444e90645d6e2785180ffe3ab0a7284793473e2d8009cad2c989d