|
|
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)
|
|