SQLite Forum

Feature request: ORDER BY with non-window aggregate functions
Login

Feature request: ORDER BY with non-window aggregate functions

(1) By anonymous on 2020-04-21 21:27:10 [source]

I would want to be able to use ORDER BY clauses in aggregate functions that aren't window functions. This is useful with some functions such as GROUP_CONCAT, but it would be useful for some other things too (especially if the window functions FIRST_VALUE, LAST_VALUE, and NTH_VALUE are made to be usable as aggregate functions too; these three window functions probably should be allowed as aggregate functions, and should allow a FILTER clause, both of these unlike the other built-in window functions for which doing these things isn't helpful). I think PostgreSQL supports ORDER BY clauses in aggregate functions, so the same syntax could be used if wanted. The syntax seems (as far as I can tell from the documentation of PostgreSQL) to be just adding the ORDER BY clause after the list of arguments but still inside of the parentheses, for example GROUP_CONCAT(X ORDER BY Y).