Skip to content

SQLite, DuckDB: Support aggregate ORDER BY without arguments - #2660

Merged
LucaCappelletti94 merged 2 commits into
mainfrom
sqlite-aggregate-order-by-no-args
Oct 24, 2026
Merged

LucaCappelletti94 merged 2 commits into
mainfrom
sqlite-aggregate-order-by-no-args

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

SQLite and DuckDB accept an aggregate call whose only content is an ORDER BY clause, such as SELECT count(ORDER BY a) FROM t, but the parser failed with Expected: ), found: BY. SQLite documents ORDER BY inside aggregate calls (https://www.sqlite.org/lang_aggfunc.html#aggorderby) and so does DuckDB (https://duckdb.org/docs/current/sql/functions/aggregates#order-by-clause-in-aggregate-functions). SQLite 3.51.1 and DuckDB 1.4.4 both run count(ORDER BY a) and count(ORDER BY a ASC, b DESC) and both reject count(DISTINCT ORDER BY a). SQLite also accepts count(ALL ORDER BY a).

A new dialect method, supports_aggregate_order_by_with_empty_args, enables the form for SQLite, DuckDB and the generic dialect. DISTINCT still requires an argument. Tests now cover every dialect on both sides of the capability.

@codecov-commenter

codecov-commenter commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.84%. Comparing base (6a8b8bb) to head (1612cae).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2660   +/-   ##
=======================================
  Coverage   81.83%   81.84%           
=======================================
  Files          42       42           
  Lines       34651    34667   +16     
  Branches    34651    34667   +16     
=======================================
+ Hits        28357    28373   +16     
  Misses       2753     2753           
  Partials     3541     3541           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-aggregate-order-by-no-args branch 2 times, most recently from f168835 to befbf87 Compare October 20, 2026 10:59
@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Oct 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 20, 2026
@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-aggregate-order-by-no-args branch from befbf87 to a43767e Compare October 21, 2026 07:34
Comment thread tests/sqlparser_common.rs
"SELECT count(*) OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) FROM t",
);
}

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.

I bet if you changed these PRs so they didn't all try and put the tests at the end of this file (put it after different other tsts) they wouldn't all conflict

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to scramble them, and it seems to have made some but little difference.

@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-aggregate-order-by-no-args branch 4 times, most recently from cd553ed to 89ca6b1 Compare October 24, 2026 07:16
@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-aggregate-order-by-no-args branch from 89ca6b1 to 1612cae Compare October 24, 2026 07:52
@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit 8fe5a1a Oct 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DuckDB enhancement New feature or request SQLite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants