Bug #91993 enhance JSON_ARRAYAGG by DISTINCT
Submitted: 13 Aug 2018 10:53 Modified: 21 Nov 2019 13:50
Reporter: Andrej Thomsen Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: JSON Severity:S4 (Feature request)
Version:8.0.12, 8.0.27 OS:Any
Assigned to: CPU Architecture:Any
Tags: distinct, json, JSON_ARRAYAGG

[13 Aug 2018 10:53] Andrej Thomsen
Description:
Some use-cases of mine require JSON-Arrays without duplicates. Since JSON_ARRAYAGG() can't do that, I often have to use some mixture of GROUP_CONCAT(DISTINCT col) with CONCAT() and then cast it as JSON. It would be great to just add "DISTINCT" into that function, like it is possible in GROUP_CONCAT().

How to repeat:
Use JSON_ARRAYAGG() with a column, which does contain non unique values.
[21 Nov 2019 13:50] MySQL Verification Team
Hi Mr. Thomson,

Thank you for your feature request.

I find your idea a good addition to the described function.

Verified as reported.
[7 Jul 2020 15:32] marcos vinicios pinheiro de sant marcos
Hello, does anyone know if this function has already been implemented in mysql?
[16 Nov 2021 12:12] MySQL Verification Team
Bug #105541 marked as duplicate of this one.
[23 Sep 2022 5:10] Tim Cool
I signed up for an oracle account, just so I could comment on this.

It appears that this issue is more than 4 years old and MariaDB has had DISTINCT within JSON_ARRAYAGG for more than 2 years.

Can you please give us an update on whether this feature is actually under serious consideration?

It would help us make an informed decision on the correct DB engine for us.
[30 Dec 2022 20:32] Sébastien F.
DISTINCT and ORDER BY clauses, just like GROUP_CONCAT(), would be great!
[31 Dec 2022 15:01] marcos vinicios pinheiro de sant marcos
Looking forward to this feature being implemented
[4 Mar 2023 8:48] Sébastien F.
Actually :

SELECT ALL CAST(CONCAT('[', GROUP_CONCAT(DISTINCT REPLACE(name, '"', '\\"') ORDER BY name ASC SEPARATOR '","'), ']') AS JSON) AS names
...

Expected :

SELECT ALL JSON_ARRAYAGG(DISTINCT name ORDER BY name ASC) AS names
...

Please!
[15 Aug 2023 17:46] Josh McCullough
Since the last comment is from March, I'll chime in ... yes please!