22013 — invalid_preceding_or_following_size
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.
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_preceding_or_following_size
- lang
- en
- sqlstate
- 22013
Definition PG 18
At a glance {#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 {#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 {#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 {#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 {#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 {#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.
Related {#related}
Sources {#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.
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": "22013 is invalid_preceding_or_following_size in SQLSTATE Class 22."
}claims · resolved-rows-groups-path
{
"claim_id": "resolved-rows-groups-path",
"limits": "This source path is limited to ROWS/GROUPS.",
"method": "Read the complete calculate_frame_offsets branches.",
"position": 1,
"runtime": [],
"sources": [
"src.window-executor.18.6"
],
"statement": "The window executor rejects negative ROWS/GROUPS start or end offsets with endpoint-specific 22013 primaries; NULL endpoints use 22004."
}claims · resolved-range-path
{
"claim_id": "resolved-range-path",
"limits": "The cited helpers are representative, not an exhaustive list of every range-capable type.",
"method": "Read the representative type-specific in_range guards.",
"position": 2,
"runtime": [],
"sources": [
"src.range-int8.18.6",
"src.range-numeric.18.6",
"src.range-float.18.6",
"src.range-timestamp.18.6"
],
"statement": "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."
}claims · history
{
"claim_id": "history",
"limits": "",
"method": "Use catalogue presence and history boundaries.",
"position": 3,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "The locked catalogue records 22013 from 11.0 without proving an exact implementation introduction date."
}messages · message.start-negative
{
"limits": "",
"message_id": "message.start-negative",
"path": "",
"position": 0,
"raw": {
"id": "message.start-negative",
"primary_template": "frame starting offset must not be negative",
"severity_source": "ERROR",
"sources": [
"src.window-executor.18.6"
],
"sqlstate": "22013"
},
"severity": "ERROR",
"sources": [
"src.window-executor.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "frame starting offset must not be negative",
"position": 0,
"role": "",
"template": "frame starting offset must not be negative"
}
]
}messages · message.end-negative
{
"limits": "",
"message_id": "message.end-negative",
"path": "",
"position": 1,
"raw": {
"id": "message.end-negative",
"primary_template": "frame ending offset must not be negative",
"severity_source": "ERROR",
"sources": [
"src.window-executor.18.6"
],
"sqlstate": "22013"
},
"severity": "ERROR",
"sources": [
"src.window-executor.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "frame ending offset must not be negative",
"position": 0,
"role": "",
"template": "frame ending offset must not be negative"
}
]
}messages · message.range-generic
{
"limits": "",
"message_id": "message.range-generic",
"path": "",
"position": 2,
"raw": {
"id": "message.range-generic",
"primary_template": "invalid preceding or following size in window function",
"severity_source": "ERROR",
"sources": [
"src.range-int8.18.6",
"src.range-numeric.18.6",
"src.range-float.18.6",
"src.range-timestamp.18.6"
],
"sqlstate": "22013"
},
"severity": "ERROR",
"sources": [
"src.range-int8.18.6",
"src.range-numeric.18.6",
"src.range-float.18.6",
"src.range-timestamp.18.6"
],
"templates": [
{
"kind": "primary",
"literal": "invalid preceding or following size in window function",
"position": 0,
"role": "",
"template": "invalid preceding or following size in window function"
}
]
}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#L183"
}sources · src.window-executor.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/executor/nodeWindowAgg.c",
"position": 1,
"sha256": "c365e6750bc77a89562254903d099c3e5914e001d3aae418322ccffc1d535d17",
"source_id": "src.window-executor.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/executor/nodeWindowAgg.c#L2144-2210"
}sources · src.range-int8.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/int8.c",
"position": 2,
"sha256": "da4d3688c0b037346f25419ea31020af9fec54021f182370234dcbf70b748f36",
"source_id": "src.range-int8.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/int8.c#L400-420"
}sources · src.range-numeric.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/numeric.c",
"position": 3,
"sha256": "6cde7cd60b3330b83be35d1f014045f5fb5fe737f3c5db4c8ed4080b99f2b666",
"source_id": "src.range-numeric.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/numeric.c#L2690-2715"
}sources · src.range-float.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/float.c",
"position": 4,
"sha256": "58914ae93c06c281e581a4bb2dcf2280e4ae1619f3ceb8f801f50beca87eecd8",
"source_id": "src.range-float.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/float.c#L1105-1125"
}sources · src.range-timestamp.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/adt/timestamp.c",
"position": 5,
"sha256": "2614ccd2182fa904b4cac9bef43039e90a1af578d2d1c6803d49a07420d168f2",
"source_id": "src.range-timestamp.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/timestamp.c#L3860-3885"
}Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · english-manuals:31787642ffd2219efb1ef4b28cca420c766afabbfb87f486cc29d6b66092efe4
Text language: en · english-manuals:31787642ffd2219efb1ef4b28cca420c766afabbfb87f486cc29d6b66092efe4