Repository navigation
fix(splitter): accept unreserved and column name keywords as CTE names - #837
Merged
Merged
Conversation
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.
The statement splitter required the CTE name to be a plain
IDENTtoken. The lexer gives every keyword its own kind, so CTEs namedconstraints,indexes,comments,functions(or any other keyword) failed withExpected IDENT/Expected AS_KW/Expected L_PAREN, although Postgres accepts them. libpg_query was never involved.Keyword categories in the lexer
The lexer codegen already reads
kwlist.hbut dropped each keyword's category. It now keeps it, andSyntaxKind::keyword_category()returns aKeywordCategory(Unreserved,ColName,TypeFuncName,Reserved). The splitter uses it to accept aColIdfor the CTE name: an identifier (quoted or not), an unreserved keyword or a column name keyword, ascommon_table_exprdoes. Reserved and type/function name keywords (select,left) are still reported, as Postgres rejects them.WITH recursive AS (...)RECURSIVEis itself unreserved, and Postgres acceptsWITH recursive AS (...)andWITH recursive(n) AS (...)as a non-recursive CTE namedrecursive. The splitter now only readsRECURSIVEas the modifier when it isn't followed byASor(.Decisions
17-latestkwlist.h, matching the parser in use. Compared with REL_18_6, every shared keyword is in the same category. The only differences are four unreserved keywords that PG 18 adds (enforced,objects,period,virtual) and one it removes (recheck), soColIdgives the same answers either way.SELECT t.update FROM t,... WHERE insert = 1,SELECT alter FROM t.SEARCH/CYCLEclauses split the statement before the mainSELECT.Regression fixtures
The Postgres regression fixtures are re-recorded for 15 to 18.
cluster.sql(WITH rows AS),with.sql(with ordinality as) and, in 18,numeric.sql(WITH rows AS) name a CTE after an unreserved keyword. The old splitter swallowed the rest of each of those files into one statement that Postgres rejected. Those statements now get their own verdicts. The typecheck snapshots only change their statement counts; the finding counts are unchanged.All statements in the new tests run on PostgreSQL 18.6 (and 15).
postgres-language-server checkon the SQL from the issue now reports no errors.Fixes #836