Repository navigation
Conversation
|
@kshvakov is attempting to deploy a commit to the coolajitpratapsingh0-9932's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
…c dialect
Two PostgreSQL grammar fixes found by running the dimitri/sqlfmt test
corpus through GoSQLX as the parsing backend of a SQL formatter, each
verified against libpg_query:
FOR UPDATE ... LIMIT: SELECT ... ORDER BY x FOR UPDATE SKIP LOCKED
LIMIT 100 is valid PostgreSQL but was rejected with E2002 at LIMIT -
the locking clause was parsed after LIMIT/OFFSET with no re-check for a
trailing limit clause. The SQL-standard order LIMIT ... FOR UPDATE was
already accepted. After the locking clause each of LIMIT / OFFSET /
FETCH FIRST may appear at most once, in any order; OFFSET combines with
either, LIMIT and FETCH are mutually exclusive (LIMIT ALL counts as a
LIMIT: it has no count and lives in Extras.LimitAll), and a limit-
clause token on both sides of the locking clause is invalid in any
combination. A duplicate token is left unconsumed for the statement
boundary, matching how a duplicate LIMIT before FOR fails. The
trailing sequence is gated to PostgreSQL plus the permissive generic
dialect: MySQL puts LIMIT before its locking clause, so FOR UPDATE ...
LIMIT keeps failing there.
CREATE OR REPLACE FUNCTION with an AS $$ ... $$ body failed when no
dialect was set ('expected semicolon or end of statement, got
REPLACE', column of REPLACE): alterMask() == dialectAll made
implicitStartWords[REPLACE] (MySQL|SQLite) match, so the generic
end-of-statement scan cut the CREATE header at its own OR REPLACE. A
word following OR never starts a new statement - nothing valid ends an
expression with a bare OR - so startsStatementInContext now continues
the statement there. Named dialects were unaffected (mask
intersection empty); the postgresql dialect parsed these statements
all along.
Also pins, as postgresql-dialect regression tests, the constructs the
corpus triage relies on: table-valued functions in FROM (including
generate_series(1, 3) AS t(x) column aliases, JOIN, subquery and
INSERT ... SELECT positions) and the <-> distance operator in every
clause position.
10 parse.golden cells regenerated (statements containing CREATE OR
REPLACE, whose recorded statement spans changed with the fix).
Changelog fragments: for-update-after-limit.added.md,
create-or-replace-function-default-dialect.added.md.
kshvakov
force-pushed
the
feat/postgres-grammar-gaps
branch
from
November 15, 2026 21:47
0d8ca78 to
edf116b
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two PostgreSQL grammar fixes found by running the dimitri/sqlfmt test
corpus through GoSQLX as the parsing backend of a SQL formatter, each
verified against libpg_query.
FOR UPDATE ... LIMIT:
SELECT ... ORDER BY x FOR UPDATE SKIP LOCKED LIMIT 100is valid PostgreSQL but was rejected withE2002atLIMIT—the locking clause was parsed after LIMIT/OFFSET with no re-check for a
trailing limit clause. The SQL-standard order
LIMIT ... FOR UPDATEwasalready accepted. After the locking clause each of
LIMIT/OFFSET/FETCH FIRSTmay appear at most once, in any order;OFFSETcombineswith either,
LIMITandFETCHare mutually exclusive, and alimit-clause token on both sides of the locking clause is invalid in any
combination. A duplicate token is left unconsumed for the statement
boundary, matching how a duplicate
LIMITbeforeFORfails. Thetrailing sequence is gated to PostgreSQL plus the permissive generic
dialect: MySQL puts
LIMITbefore its locking clause, soFOR UPDATE ... LIMITkeeps failing there.CREATE OR REPLACE FUNCTION with an
AS $$ ... $$body failed when nodialect was set (
expected semicolon or end of statement, got REPLACE):alterMask() == dialectAllmadeimplicitStartWords[REPLACE](MySQL|SQLite) match, so the generic end-of-statement scan cut the CREATE
header at its own
OR REPLACE. A word followingORnever starts a newstatement — nothing valid ends an expression with a bare
OR— sostartsStatementInContextnow continues the statement there. Nameddialects were unaffected; the postgresql dialect parsed these statements
all along.
Also pins, as postgresql-dialect regression tests, the constructs the
corpus triage relies on: table-valued functions in FROM (including
generate_series(1, 3) AS t(x)column aliases, JOIN, subquery andINSERT ... SELECTpositions) and the<->distance operator in everyclause position.
10 parse.golden cells regenerated (statements containing CREATE OR
REPLACE, whose recorded statement spans changed with the fix).
Changelog fragments:
for-update-after-limit.added.md,create-or-replace-function-default-dialect.added.md.