42601
Read PG 18 manual ↗syntax_error
- SQLSTATE
- 42601
- Condition name
- syntax_error
- Class
- Syntax Error or Access Rule Violation
- Source macro
- ERRCODE_SYNTAX_ERROR
- Evidence
- Observed at runtime in the source evidence
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
At a glance
SQLSTATE 42601 is syntax_error in Class 42. 42601 is a syntax error. The selected parser path rejects LIMIT 1, 2 with primary LIMIT #,# syntax is not supported and hint Use separate LIMIT and OFFSET clauses.
Meaning
42601 is a syntax error. In the selected gram.y action, the comma form is rejected during parsing with the ERROR primary LIMIT #,# syntax is not supported and hint Use separate LIMIT and OFFSET clauses. The comma form is therefore not a request for “offset 1, then take 2” in PostgreSQL; the two values must be written as separate clauses.
The scanner and grammar share a general 42601 path. scanner_yyerror sets the SQLSTATE and reports either syntax error at or near "%s" for the current token or syntax error at end of input when the scanner is at the buffer end, with a lexer position. Grammar actions can supply a more specific message through the same formatter. The selected LIMIT branch is one producer among these parser and scanner branches, not a requirement for every 42601.
Diagnosis
Capture the exact statement, parser position, server version, and hint. For at or near, inspect the token named by POSITION and the text immediately before it; for at end of input, check an unclosed quote, dollar-quote, parenthesis, comment, or generated clause. Preserve the exact bytes sent by the query builder, including delimiters and substituted fragments, and replay that statement through the server parser before changing semantics. The parser rejects this grammar before execution, so the selected autocommit session remains IDLE and no rows are produced by the failed statement. In an explicit transaction, the same statement-level ERROR leaves the transaction in its failed state until ROLLBACK or an appropriate savepoint action; that is a different session boundary from the selected autocommit observation. Do not confuse a grammar error with an undefined object or a feature recognized but unsupported in its context.
Response
Rewrite the statement using the grammar named by the hint. For the selected ordered three-row query, LIMIT 1, 2 becomes LIMIT 2 OFFSET 1 and returns rows [2, 3]; LIMIT 1 OFFSET 0 would be a different result and is not an equivalent repair. Keep query builders version-aware when they emit dialect-specific pagination.
For a generic scanner error, repair the missing or misplaced token, quote, comment delimiter, or query-builder fragment identified by the position, then parse the complete statement again. Do not apply the LIMIT rewrite to a different 42601 message merely because it shares the SQLSTATE.
Messages
The selected parser branch raises an explicit ERROR with primary LIMIT #,# syntax is not supported and HINT Use separate LIMIT and OFFSET clauses. The scanner's generic fixed branches use syntax error at or near "%s" or syntax error at end of input, with the position generated from the lexer. The LIMIT primary/HINT identify the selected pagination subpath; a client exception without the server SQLSTATE and the diagnostics for the specific branch is not sufficient to identify that subpath, while other valid 42601 producers may have different primaries.
Representative case
The page uses the same statements as the runner registry. Generated names such as syntax_schema and syntax_role are replaced by disposable runner values when executed.
SELECT n FROM generate_series(1, 3) AS s(n) ORDER BY n LIMIT 1, 2;
SELECT n FROM generate_series(1, 3) AS s(n) ORDER BY n LIMIT 2 OFFSET 1;
The selected 18.6 run reports the structured diagnostic and passes the repair assertions; the 10.21 run passes the same case-specific checks. The downloadable case and evidence projections are 42601 case JSON and authored evidence. The runner manifest is verify/cases/42601/cases.json, and the page SQL is checked against its shared registry.
Versions
The selected natural runtime scope is PostgreSQL 18.6 and 10.21; it does not infer behavior for every intermediate release.
Sources
src.errcodes.18.6— fixederrcodes.txtdefinition at commit724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(source).src.limit-comma.18.6—src/backend/parser/gram.yatREL_18_6commit724edf9bde9d356724ad384a2e196edc3c9f80f7; fixed blob SHA-2567e548b673a1e03eb3a56c5eb9ad92d8e11095fac76e14cb258ca851f58274724(source).src.limit-comma.10.23—src/backend/parser/gram.yatREL_10_23commit02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4; fixed blob SHA-256cebad6a5a2bdf68e9e5a4d2e04fa7f5dbf37efac99f5edb73cc661dae1536bad(source).src.scanner-syntax.18.6/src.scanner-syntax.10.23— fixedsrc/backend/parser/scan.lscanner_yyerrorbranches forat end of inputandat or near; blob SHA-256bf453f1ae3c22b84fea6f8e8bed4fda476b7cfa49b234efbf92ca228234d0293/a006581a25c659d59b29837010617503ff431f881e3cf0b54a99aa1cc445fe6c(18.6 source, 10.23 source).src.calls.REL_18_6/src.calls.REL_10_23— fixed call scans, SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf/00d16d3eb01b71ccf1b245c8f3102f9d0ec9f36fb02777b8dd1b99fcb263040c.
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
42601 is the syntax_error condition in Class 42.
Method: Read fixed errcodes.txt and the locked catalogue metadata.
Limits: Directory identity does not identify every backend path.
The fixed source calls for 42601 include the mechanism and message boundary selected for this page.
Method: Trace the resolved REL_18_6 and REL_10_23 source call records at the locked commits.
Limits: Other calls can use the same SQLSTATE with different context or dynamic fields.
src.limit-comma.18.6 src.limit-comma.10.23 src.scanner-syntax.18.6 src.scanner-syntax.10.23
The fixed scanner formats generic syntax errors as at-or-near-token or end-of-input errors and attaches a lexer position.
Method: Read scanner_yyerror and scanner_errposition in the fixed REL_18_6 and REL_10_23 scan.l sources.
Limits: This source branch is separate from the selected LIMIT runtime; grammar actions can supply more specific primary text.
The selected syntax_limit_comma case passed on isolated PostgreSQL 18.6 and 10.21 targets.
Method: Run the shared registry case and inspect structured diagnostics, state/recovery assertions, and cleanup.
Limits: This covers the selected case and targets only; it does not generalize to all drivers or intermediate releases.
The locked catalogue records 42601; runtime scope is limited to the selected targets.
Method: Read generated facts and selected summaries.
Limits: Definition presence is not an exact behavioral introduction.
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 raw/calls/REL_18_6.jsonl· ·raw/calls/REL_10_23.jsonl· ·- src/backend/parser/gram.y · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/gram.y · REL_10_23 ·
02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4 - src/backend/parser/scan.l · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/scan.l · REL_10_23 ·
02991e79f8f58bc208f05dcc8af0c62dbe0a6ea4 verify/cases/42601/cases.json· ·verify/cases/42601/snippets.json· ·
Message templates
explicit ERROR · message.limit-comma
Primary
LIMIT #,# syntax is not supported
Hint
Use separate LIMIT and OFFSET clauses.
explicit ERROR · message.scanner-generic
Primary
syntax error at or near "%s"
Primary
syntax error at end of input
The scanner inserts the grammar/lexer message and dynamic token; these variants are source-only in this batch.
Reproduction & repair cases
syntax_limit_comma · PG 10, 18
Preconditions
- A runner-owned disposable target is provisioned with a deterministic three-row ordered query.
Trigger: Execute the unsupported comma form over ordered rows: SELECT n FROM generate_series(1, 3) AS s(n) ORDER BY n LIMIT 1, 2.
Expected assertions
- SQLSTATE is 42601 with the LIMIT #,# diagnostic
- The autocommit session remains IDLE
- Separate LIMIT and OFFSET syntax returns the second and third rows [2, 3]
Repair: Use separate LIMIT and OFFSET clauses as indicated by the server hint.
Cleanup: No persistent objects; close the runner connection.
Recorded runtime evidence
18.6 (Homebrew) · passed
Run: 42601-pagination-semantics-latest
{
"diagnostic": {
"text": "LIMIT #,# syntax is not supported\nLINE 1: ...T n FROM generate_series(1, 3) AS s(n) ORDER BY n LIMIT 1, 2\n ^\nHINT: Use separate LIMIT and OFFSET clauses.",
"context": null,
"severity": "ERROR",
"sqlstate": "42601",
"table_name": null,
"column_name": null,
"schema_name": null,
"source_file": "gram.y",
"source_line": "13317",
"message_hint": "Use separate LIMIT and OFFSET clauses.",
"datatype_name": null,
"exception_type": "SyntaxError",
"internal_query": null,
"message_detail": null,
"constraint_name": null,
"message_primary": "LIMIT #,# syntax is not supported",
"source_function": "base_yyparse",
"internal_position": null,
"statement_position": "56",
"severity_nonlocalized": "ERROR"
},
"repair_rows": [
2,
3
],
"failed_status": "IDLE",
"repair_status": "IDLE",
"connection_autocommit": true
}10.21 (Debian 10.21-1.pgdg90+1) · passed
Run: 42601-pagination-semantics-pg10
{
"diagnostic": {
"text": "LIMIT #,# syntax is not supported\nLINE 1: ...T n FROM generate_series(1, 3) AS s(n) ORDER BY n LIMIT 1, 2\n ^\nHINT: Use separate LIMIT and OFFSET clauses.",
"context": null,
"severity": "ERROR",
"sqlstate": "42601",
"table_name": null,
"column_name": null,
"schema_name": null,
"source_file": "gram.y",
"source_line": "11203",
"message_hint": "Use separate LIMIT and OFFSET clauses.",
"datatype_name": null,
"exception_type": "SyntaxError",
"internal_query": null,
"message_detail": null,
"constraint_name": null,
"message_primary": "LIMIT #,# syntax is not supported",
"source_function": "base_yyparse",
"internal_position": null,
"statement_position": "56",
"severity_nonlocalized": "ERROR"
},
"repair_rows": [
2,
3
],
"failed_status": "IDLE",
"repair_status": "IDLE",
"connection_autocommit": true
}Definition snapshot: english-manuals:a0c67dc4885a1b577592f6c6534… · English manual source