Introduce ordered set aggregate functions #4127
Replies: 1 comment
-
See #4758 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The idea is to extend HQL to accept the syntax
function_name(DISTINCT? args*) WITHIN GROUP (ORDER BY ...)
for functions that are ordered set aggregate functions. Here is a nice explanation of ordered set aggregate functions and specifically, the interestinglistagg
variant for which we need a special grammar rule because it also has anON OVERFLOW
clause: https://modern-sql.com/feature/listaggThe emulation of the
listagg
function can easily be done on most databases through the use of the various vendor specific versions e.g.string_agg
andgroup_concat
. Emulating the function with a recursive CTE is also possible but probably not practical, so for databases that do not support this function, we should simply provide an error.Out of the databases that we have in hibernate-core (the others are now in hibernate-community-dialects), the following databases do not support the string aggregation:
It might be possible to implement UDFs to emulate this function, but that is out of scope.
Apart from the standard
listagg
function, I propose we also add the following functions (without emulation, at least for now) which are nicely explained in the PostgreSQL documentation (https://www.postgresql.org/docs/13/functions-aggregate.html#FUNCTIONS-ORDEREDSET-TABLE):mode
percentile_cont
percentile_disc
And the following hypothetical set aggregate functions (https://www.postgresql.org/docs/13/functions-aggregate.html#FUNCTIONS-HYPOTHETICAL-TABLE):
rank
dense_rank
percent_rank
cume_dist
Beta Was this translation helpful? Give feedback.
All reactions