Skip to content

Support Oracle KEEP (DENSE_RANK ... FIRST/LAST ... ) syntax - #7950

Merged
keraion merged 1 commit into
sqlfluff:mainfrom
GHRF:ghrf/fix-oracle-keep-dense-rank
Jun 14, 2026
Merged

keraion merged 1 commit into
sqlfluff:mainfrom
GHRF:ghrf/fix-oracle-keep-dense-rank

Conversation

@GHRF

@GHRF GHRF commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Brief summary of the change made

Fixes #7947

Oracle has a unique syntax surrounding the use of the analytic functions FIRST and LAST.
This PR provides support for the syntax, as described by the oracle documentation.

Are there any other side effects of this change that we should be aware of?

There should not be any.
This only adds a new possible clause behind functions, analogous to already supported WITHIN GROUP or FILTER (...).

I did read up on any relevant documentation pertaining to contributing, but I may have missed some things. If anything in this PR does not meet standard please let me know as this is a first !

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.

AI use disclosure

Agentic AI was used for discovery of the project and a first draft of the changes. These proposed changes were all manually checked. The queries were hand-written from the oracle documentation, then tested.


Summary by cubic

Adds Oracle KEEP (DENSE_RANK FIRST/LAST ORDER BY ...) parsing to the Oracle dialect so aggregate/window functions can use KEEP correctly. Fixes #7947.

  • New Features
    • Introduced KeepClauseSegment and allowed it in PostFunctionGrammar after functions.
    • Supports FIRST/LAST with ORDER BY and NULLS FIRST/LAST, including use with OVER().
    • Added parser fixtures covering GROUP BY and windowed examples.

Written for commit f38aa2f. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

@keraion keraion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Thanks for the contribution!

@keraion
keraion added this pull request to the merge queue Jun 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Results ✅

Name    Stmts   Miss  Cover   Missing
-------------------------------------
TOTAL   21955      0   100%

265 files skipped due to complete coverage.

Merged via the queue into sqlfluff:main with commit 1bdffed Jun 14, 2026
48 checks passed
benfdking added a commit to quarylabs/sqruff that referenced this pull request Oct 5, 2026
Parse KEEP (DENSE_RANK FIRST/LAST ORDER BY ...) after Oracle aggregate functions, including the OVER form. Add DENSE_RANK keyword, semantic classification, and upstream parser fixture.

Upstream SHA: 1bdffedcc46d6ca97b1be53f960dfcd4618d4693

Upstream PR: sqlfluff/sqlfluff#7950

Upstream commit: sqlfluff/sqlfluff@1bdffed
benfdking added a commit to quarylabs/sqruff that referenced this pull request Oct 5, 2026
Parse KEEP (DENSE_RANK FIRST/LAST ORDER BY ...) after Oracle aggregate functions, including the OVER form. Add DENSE_RANK keyword, semantic classification, and upstream parser fixture.

Upstream SHA: 1bdffedcc46d6ca97b1be53f960dfcd4618d4693

Upstream PR: sqlfluff/sqlfluff#7950

Upstream commit: sqlfluff/sqlfluff@1bdffed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[oracle] unparsable section on max(...) KEEP (DENSE_RANK FIRST/LAST ... ORDER BY ...)

2 participants