[MDEV-29472] JSON_EXTRACT surprising auto-wrap Created: 2022-09-06  Updated: 2023-03-21  Resolved: 2023-03-21

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.9.2
Fix Version/s: 10.9.5

Type: Bug Priority: Major
Reporter: Markus Winand Assignee: Rucha Deodhar
Resolution: Fixed Votes: 0
Labels: None


 Description   

The sequence of statements below yields a strange result, in particular it is also different from previous MariaDB versions (namely, 10.8.3).

I believe the wildcard member accessory should always apply an auto-wrap, but the but I get one row wrapped, the second one not. I would expect both being wrapped, thus instead of "20" I'd expect "[20]".

MariaDB 5.5.5-10.9.2-MariaDB>  CREATE TABLE demo_json_z2o1 (
    ->      id NUMERIC NOT NULL,
    ->      j VARCHAR(255)
    ->  );
Query OK, 0 rows affected (0.00 sec)
 
MariaDB 5.5.5-10.9.2-MariaDB> INSERT INTO demo_json_z2o1 (id, j) VALUES (1,'{"a": 10}');
Query OK, 1 row affected (0.00 sec)
 
MariaDB 5.5.5-10.9.2-MariaDB> INSERT INTO demo_json_z2o1 (id, j) VALUES (2,'{"b": 20}');
Query OK, 1 row affected (0.00 sec)
 
MariaDB 5.5.5-10.9.2-MariaDB>  SELECT id
    ->       , JSON_EXTRACT(j, '$.*') val
    ->    FROM demo_json_z2o1
    ->   ORDER BY id;
+----+------+
| id | val  |
+----+------+
|  1 | [10] |
|  2 | 20   |
+----+------+
2 rows in set (0.00 sec)
 
MariaDB 5.5.5-10.9.2-MariaDB>



 Comments   
Comment by Rucha Deodhar [ 2023-03-21 ]

Already fixed on 10.9
output on my laptop (latest 10.9)

CREATE TABLE demo_json_z2o1 (
id NUMERIC NOT NULL,
j VARCHAR(255)
);
INSERT INTO demo_json_z2o1 (id, j) VALUES (1,'{"a": 10}');
INSERT INTO demo_json_z2o1 (id, j) VALUES (2,'{"b": 20}');
SELECT id
, JSON_EXTRACT(j, '$.*') val
FROM demo_json_z2o1
ORDER BY id;
id	val
1	[10]
2	[20]
DROP TABLE demo_json_z2o1;

Generated at Thu Feb 08 10:08:52 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.