Bug #113921 JSON_ARRAYAGG - ordering elements
Submitted: 8 Feb 2024 1:28 Modified: 8 Feb 2024 6:38
Reporter: Ryan Brothers Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: JSON Severity:S4 (Feature request)
Version:8.3.0 OS:Any
Assigned to: CPU Architecture:Any

[8 Feb 2024 1:28] Ryan Brothers
Description:
This is a feature request.

Per the documentation, when using the function JSON_ARRAYAGG, the order of elements is undefined.

Since an array is an ordered list of items, would it be possible to add ORDER BY support to JSON_ARRAYAGG like GROUP_CONCAT allows?  For example:

JSON_ARRAYAGG(table1.field_name ORDER BY table1.field_name)

The workaround I do now is:

CONCAT('[', GROUP_CONCAT(table1.field_name ORDER BY table1.field_name SEPARATOR ','), ']')

Thank you for your help.

How to repeat:
.
[8 Feb 2024 6:38] MySQL Verification Team
Hello Ryan,

Thank you for the feature request!

regards,
Umesh
[20 Jun 2024 9:07] Евгений Орещенко
I agree, this is a very useful feature, especially when GROUP_CONCAT has a length limit by default. I'm really waiting for ORDER BY support in JSON_ARRAYAGG.