persistence icon indicating copy to clipboard operation
persistence copied to clipboard

Add a listagg/groupconcat function to CriteriaBuilder

Open AleksNo opened this issue 5 years ago • 4 comments

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

AleksNo avatar Nov 06 '19 20:11 AleksNo

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.

gavinking avatar May 05 '21 11:05 gavinking

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.

beikov avatar May 05 '21 12:05 beikov

SQL standard LISTAGG

My bad, I was wrong.

gavinking avatar May 05 '21 12:05 gavinking

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.

beikov avatar Mar 18 '22 12:03 beikov