Skip to content

Group date-part aliases in SELECT projections - #911

Open
SAY-5 wants to merge 1 commit into
andialbrecht:masterfrom
SAY-5:say5/fix-select-keyword-aliases-20260928
Open

SAY-5 wants to merge 1 commit into
andialbrecht:masterfrom
SAY-5:say5/fix-select-keyword-aliases-20260928

Conversation

@SAY-5

@SAY-5 SAY-5 commented Sep 28, 2026

Copy link
Copy Markdown

Thanks for contributing!

Before submitting your pull request please have a look at the
following checklist:

  • ran the tests (pytest)
  • all style issues addressed (ruff)
  • your changes are covered by tests
  • your changes are documented, if needed

In addition, please take care to provide a proper description
on what your change does, fixes or achieves when submitting the
pull request.

Fixes #781.

SELECT EXTRACT(YEAR FROM foo) year, EXTRACT(MONTH FROM foo) month, value FROM orders now produces one projection list with year and month aliases. Previously the aliases split the projection into separate groups and get_alias() did not return them.

Recognize the six date-part keywords only after a bare function at a SELECT-item boundary, with a following projection or clause boundary. Keep interval constructors and their units intact, including INTERVAL (ABS(-1)) DAY; quoted function names remain distinguishable. The tests also cover scalar-literal predecessors, explicit aliases, nested SELECTs, window functions and JOIN/UNION clauses.

This is a bounded grouping fix. Unknown clause keywords stop recognition; comment-separated aliases and broader keyword-alias grammar remain outside its scope.

On Python 3.13.0, the full suite reports 555 passed, 2 expected failures and 1 unexpected pass; the expected-failure statuses match upstream. Against the original source, 40 alias regression cases fail, and an additional formatter regression reproduces the excessive indentation in #781. ruff check sqlparse/ passes. The repository's grouping benchmarks and a function-alias projection benchmark report linear scaling. The other Python/OS combinations are left to hosted CI.


Note: This repository has automated AI code reviews enabled to help catch
potential issues early and provide suggestions. This is an experimental
feature to support maintainers and contributors – your feedback is welcome!

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.

Parsing error with aliased functions

1 participant