fix: SELECT DISTINCT parsing in Postgres dialect#2304
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
Benchmark for 572a0c7Click to view benchmark
|
Contributor
Benchmark for 450266aClick to view benchmark
|
Contributor
Benchmark for 41256b6Click to view benchmark
|
…lects The Postgres SelectClauseModifierSegment grammar required DISTINCT to be followed by ON (...), making plain SELECT DISTINCT unparsable. This affected all dialects inheriting from Postgres (DuckDB, Redshift). Mark the ON (...) sequence as optional so both DISTINCT and DISTINCT ON (...) are valid. https://claude.ai/code/session_01GohGSsbQjCDEjukcAbk6Ux
…RACT Adds test cases covering: - SELECT DISTINCT in a subquery with LEFT JOIN and BETWEEN - SELECT DISTINCT with EXTRACT, CTEs, CROSS JOIN, and UNION ALL These reproduce the parsing errors that were fixed by making the ON (...) sequence optional in the Postgres SelectClauseModifierSegment. https://claude.ai/code/session_01GohGSsbQjCDEjukcAbk6Ux
Move the new test fixtures from sqlfluff/ to sqruff/ subfolder, matching the convention used by other dialects (clickhouse, postgres, sqlite) for sqruff-originated test cases. https://claude.ai/code/session_01GohGSsbQjCDEjukcAbk6Ux
2ee8e36 to
1a9fdb5
Compare
Contributor
Benchmark for 2138d4eClick to view benchmark
|
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.
Summary
Fixed parsing of the
DISTINCTkeyword in SELECT statements to be recognized as a select clause modifier rather than a function name, aligning with SQL standard syntax.Key Changes
DISTINCTmay or may not be presentDISTINCTis now recognized as aselect_clause_modifierkeyword instead of being incorrectly parsed as afunction_name_identifierImplementation Details
postgres.rsadds.config(|this| this.optional())to the select clause modifier matcher, allowing the parser to correctly handle SELECT statements with or without modifiersDISTINCTappears as a sibling keyword modifier to the select clause, not as part of a function expressionhttps://claude.ai/code/session_01GohGSsbQjCDEjukcAbk6Ux