persistence
persistence copied to clipboard
Add a listagg/groupconcat function to CriteriaBuilder
Hi, sometimes i miss a listagg function in JPA. It is nice for summarizing some lists and present them to the user.
A good explanation what it does is here: https://www.w3resource.com/mysql/aggregate-functions-and-grouping/aggregate-functions-and-grouping-group_concat.php
The syntax would be: Expression listagg(Expression expr, String separator)
The usage would be: cb.listagg(MyEntity_.stringValue, ", ");
And a kind of distinctlistagg(Expression expr, String separator) would be nice too. It can happen that the concatenated String contains duplicates. They should be removed with distinctlistagg.
Greetings
This seems like a feature that's very specific to MySQL, and should not be added to JPA.
I believe this issue should be closed.
It's not specific to MySQL. The big vendors all offer the SQL standard LISTAGG or some vendor specific version of it. In general, the SQL standard calls these kinds of functions "ordered set-aggregate functions" and I think that especially LISTAGG is one of the functions that is really useful.
SQL standard
LISTAGG
My bad, I was wrong.
FWIW Hibernate 6.0 supports listagg
in HQL. If anyone is willing to work on the spec parts, Hibernate can serve as a compatible implementation.