Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Duplicate
-
None
-
None
-
Not for Release Notes
Description
Like the non-aggregate JSON_OBJECT (MDEV-40979), JSON_OBJECTAGG emits an object with duplicate keys when the aggregated key column contains the same key more than once, which violates RFC 8259 ("names within an object should be unique").
Reproduced on 10.11.19 and on 13.1 (debug builds):
CREATE TABLE mo (id INT, k VARCHAR(4), v INT); |
INSERT INTO mo VALUES (1,'a',1),(3,'a',3),(2,'b',2); |
|
|
SELECT JSON_OBJECTAGG(k, v) FROM mo WHERE id IN (1,3); |
-- {"a":1, "a":3}
|
|
|
SELECT JSON_VALID(JSON_OBJECTAGG(k, v)) FROM mo WHERE id IN (1,3); |
-- 1
|
The result has two members named "a", and JSON_VALID accepts it. MySQL 8.0 returns "a": 3 for the same aggregate (the last value wins). The aggregate takes a separate code path from the JSON_OBJECT constructor (Item_func_json_objectagg), so the fix for MDEV-40979 will not cover it.
Attachments
Issue Links
- duplicates
-
MDEV-40979 JSON_OBJECT duplicate keys produce an invalid JSON document (RFC 8259 violation)
-
- Confirmed
-