[MDEV-22300] JSON_TABLE: If value extracted for regular column is array, the first element is returned instead of error Created: 2020-04-18  Updated: 2020-06-05  Resolved: 2020-06-05

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: N/A
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-17399 Add support for JSON_TABLE Closed

 Description   

bb-10.5-hf 6dfb3fab2

MariaDB [test]> select * from json_table('{"a":"foo","b":"bar"}', '$' columns (v varchar(20) path '$.*')) as jt;
+------+
| v    |
+------+
| foo  |
+------+
1 row in set (0.002 sec)
 
MariaDB [test]> select * from json_table('{"a":"foo","b":"bar"}', '$' columns (v varchar(20) path '$.*' default '100' on error)) as jt;
+------+
| v    |
+------+
| foo  |
+------+
1 row in set (0.002 sec)

The value extracted from JSON text above is an array:

MariaDB [test]> select json_extract('{"a":"foo","b":"bar"}','$.*');
+---------------------------------------------+
| json_extract('{"a":"foo","b":"bar"}','$.*') |
+---------------------------------------------+
| ["foo", "bar"]                              |
+---------------------------------------------+
1 row in set (0.001 sec)

Based on MySQL documentation (and less obviously on the standard), only scalar values are allowed, and an error should be returned upon an array, like this:

MySQL 8.0.19

MySQL [test]>  select *  from json_table('{"a":"foo","b":"bar"}', '$' columns (v varchar(20) path '$.*')) as jt1 limit 2;
+------+
| v    |
+------+
| NULL |
+------+
1 row in set (0.000 sec)
 
MySQL [test]>  select *  from json_table('{"a":"foo","b":"bar"}', '$' columns (v varchar(20) path '$.*' default '100' on error)) as jt1;
+------+
| v    |
+------+
| 100  |
+------+
1 row in set (0.001 sec)



 Comments   
Comment by Alexey Botchkov [ 2020-06-05 ]

fixed to work as Oracle.
I wonder though if it's better to just disallow wildcards in the column's paths?

Generated at Thu Feb 08 09:13:42 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.