Bug #90835 NULL treatment of JSON_ARRAYAGG
Submitted: 11 May 2018 12:01 Modified: 12 May 2018 16:44
Reporter: Markus Winand Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: JSON Severity:S3 (Non-critical)
Version:5.7/8.0 OS:Any
Assigned to: CPU Architecture:Any

[11 May 2018 12:01] Markus Winand
Description:
The JSON_ARRAYAGG function uses a standard SQL name, but doesn't apply the NULL handling as mandated by the standard.

Note that this is not about the absence of the <JSON constructor null clause> clause in MySQL, but that MySQL uses "NULL ON NULL" instead of the standard-mandated "ABSENT ON NULL" handing in lack of an explicit <JSON constructor null clause>.

Example:

SELECT JSON_ARRAYAGG(c)
  FROM (SELECT 1 c
         UNION ALL
        SELECT null c) t

+------------------+
| JSON_ARRAYAGG(c) |
+------------------+
| [1, null]        |
+------------------+

As per the standard, the result should be "[1]" because NULL values are removed.

Whether or not you want to comply with the SQL standard is really up to you, but IMHO you should not diverge from standard behaviour if you are using standard function names.

SQL-2:2016 10.11 SR 5a says for JSON_ARRAYAGG "If <JSON constructor null clause> is not specified, then ABSENT ON NULL is implicit."

SQL-2:2016 10.11 GR 5 g ii 2 removes the NULL values from the result if  <JSON constructor null clause> is other than NULL ON NULL.

How to repeat:
Run the above query.
[12 May 2018 16:44] Miguel Solorzano
Thank you for the bug report.