Skip to content

Fix grouping of WITHIN GROUP aggregates - #905

Open
banlor wants to merge 1 commit into
andialbrecht:masterfrom
banlor:fix/within-group-700
Open

banlor wants to merge 1 commit into
andialbrecht:masterfrom
banlor:fix/within-group-700

Conversation

@banlor

@banlor banlor commented Sep 16, 2026

Copy link
Copy Markdown

Group WITHIN GROUP (...) with its aggregate before resolving column aliases. This fixes LISTAGG(...) WITHIN GROUP(...) AS name being split into two columns.

The grouping also handles an optional OVER clause, comments between clauses, nested aggregates and parameter extraction. WITHIN on its own remains usable as an alias.

Fixes #700.

Tested on Windows with Python 3.11: pytest tests/ and ruff check sqlparse/.

  • ran the tests (pytest)
  • all style issues addressed (ruff)
  • changes are covered by tests
  • changes are documented in the changelog

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.

Incorrect parsing of string aggregation with group ordering ("LISTAGG(...) WITHIN GROUP(ORDER BY ... )")

1 participant