Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.5.5, 10.2, 10.3, 10.4, 10.5
-
None
-
None
Description
Consider the following:
> SELECT JSON_EXTRACT('{ "a":1, "b":2}', '$.b', '$.a');
|
+-----------------------------------------------+
|
| JSON_EXTRACT('{ "a":1, "b":2}', '$.b', '$.a') |
|
+-----------------------------------------------+
|
| [1, 2] |
|
+-----------------------------------------------+
|
1 row in set (0.000 sec)
|
 |
MariaDB [(none)]> SELECT JSON_EXTRACT('{ "a":1, "b":2}', '$.a', '$.b');
|
+-----------------------------------------------+
|
| JSON_EXTRACT('{ "a":1, "b":2}', '$.a', '$.b') |
|
+-----------------------------------------------+
|
| [1, 2] |
|
+-----------------------------------------------+
|
1 row in set (0.000 sec)
|
The selected field values are returned in the order in which they appear in the document, and not in the order of the path arguments given to JSON_EXTRACT.
The documentation at https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-extract states If it is possible that those arguments could return multiple values, the matched values are autowrapped as an array, in the order corresponding to the paths that produced them.
Indeed, unless that is done, multiple path arguments cannot be used, as you will not know which returned value corresponds to which path.