Bug #46176 Aggregate function for strings (Concatenation)
Submitted: 14 Jul 2009 15:42 Modified: 14 Jul 2009 20:01
Reporter: joerg gottschlich Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S4 (Feature request)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: aggregate strings concatenate char varchar

[14 Jul 2009 15:42] joerg gottschlich
Description:
There should be an aggregate function for strings which can be conveniently used to concatenate the different values of a text field when grouping, e.g. like

SELECT key1,
       key2
       SUM(some_numeric_field),
       MAX(some_other_field),
       CONCAGGREGATE(some_text_field, ", ")
FROM aTable
GROUP BY key1, key2;

Now assume that some_text_field has the following (distinct) values:
abc
def
ghi

Then the result of CONCAGGREGATE(some_text_field, ", ") should be:
"abc, def, ghi"
- it concatenates the strings with the given separator
(of course the function can and should have a prettier name).

That would be a very convenient feature for cases, where you want to quickly include the values from a text field into a rollup for informational purposes without a big fuss like concatenating separately or similar.

That would be a truly pragmatic and innovative feature. Thanks.

How to repeat:
n/a

Suggested fix:
Sorry if there is already a possibility to do this; I'm not aware of one.
[14 Jul 2009 20:01] joerg gottschlich
sorry, I've just noticed that there is already the GROUP_CONCAT function. Sorry!