[MDEV-26448] CAST as JSON is not supported Created: 2021-08-20  Updated: 2021-09-09  Resolved: 2021-08-20

Status: Closed
Project: MariaDB Server
Component/s: N/A
Affects Version/s: 10.6.3, 10.6.5
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Valerii Kravchuk Assignee: Sergei Golubchik
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

MariaDB does have a JSON data type implemented, with a lot of features added over time, but unlike MySQL 8.0.x it does not support casting to JSON (since MDEV-11439 is fixed, probably). Consider this:

openxs@ao756:~/dbs/8.0$ bin/mysql --socket=/tmp/maysql8.sock -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.26 Source distribution
 
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> select cast(true as json);
+--------------------+
| cast(true as json) |
+--------------------+
| true               |
+--------------------+
1 row in set (0,00 sec)

and compare to the following MariaDB behavior:

openxs@ao756:~/dbs/8.0$ bin/mysql --socket=/tmp/mariadb.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.5-10.6.5-MariaDB MariaDB Server
 
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> select cast(true as json);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json)' at line 1
mysql> select cast(true as text);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'text)' at line 1
mysql> select cast(true as unsigned);
+------------------------+
| cast(true as unsigned) |
+------------------------+
|                      1 |
+------------------------+
1 row in set (0,00 sec)
 
mysql> select cast(true as char);
+--------------------+
| cast(true as char) |
+--------------------+
| 1                  |
+--------------------+
1 row in set (0,00 sec)

It is unexpected I'd say to have no way to cast to JSON (or, for that matter, TEXT) type when cast to CHAR is supported.



 Comments   
Comment by Sergei Golubchik [ 2021-08-20 ]

This is intentional, we cannot have CAST AS something that is not a data type. Use JSON_COMPACT() or something.

If you'd like, create a new feature request "add JSON data type" — that will mean that CAST should work too.

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