pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.94k stars 5.81k forks source link

A minor compatible issue when binary string is used for json_unquote #25580

Open guo-shaoge opened 3 years ago

guo-shaoge commented 3 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

SELECT JSON_UNQUOTE(CAST('ABCD' AS BINARY));

2. What did you expect to see? (Required)

mysql> SELECT JSON_UNQUOTE(CAST('ABCD' AS BINARY));
ERROR 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.

3. What did you see instead (Required)

mysql> SELECT JSON_UNQUOTE(CAST('ABCD' AS BINARY));
+--------------------------------------+
| JSON_UNQUOTE(CAST('ABCD' AS BINARY)) |
+--------------------------------------+
| ABCD                                 |
+--------------------------------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

master

YangKeao commented 2 years ago

@xiongjiwei tells it's expected to implicitly cast the string to json opaque. However, the implementation of TiDB is still different:

mysql> SELECT JSON_UNQUOTE(CAST(CAST('ABCD' AS BINARY) AS JSON));
+----------------------------------------------------+
| JSON_UNQUOTE(CAST(CAST('ABCD' AS BINARY) AS JSON)) |
+----------------------------------------------------+
| base64:type253:QUJDRA==                            |
+----------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT JSON_UNQUOTE(CAST('ABCD' AS BINARY));
+--------------------------------------+
| JSON_UNQUOTE(CAST('ABCD' AS BINARY)) |
+--------------------------------------+
| ABCD                                 |
+--------------------------------------+
1 row in set (0.00 sec)

It's actually not implicitly casted to json, but return the string directly. @xiongjiwei How do you think about it?

xiongjiwei commented 2 years ago

I will take a look and fix it

dveeden commented 3 months ago

@xiongjiwei is this still something you're working on?