Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON_LENGTH, JSON_DEPTH, JSON_INSERT, JSON_QUOTE shouldn't implicitly cast argument to json #59462

Open
Tracked by #59410
YangKeao opened this issue Feb 11, 2025 · 1 comment
Assignees
Labels
component/expression component/json sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@YangKeao
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

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

mysql> SELECT JSON_LENGTH(123);
ERROR 3146 (22032): Invalid data type for JSON data in argument 1 to function json_length; a JSON string or JSON type is required.
mysql> SELECT JSON_LENGTH(123.45);
ERROR 3146 (22032): Invalid data type for JSON data in argument 1 to function json_length; a JSON string or JSON type is required.
mysql> SELECT JSON_LENGTH(CAST('{"i": 0}' 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_LENGTH(123);
+------------------+
| JSON_LENGTH(123) |
+------------------+
|                1 |
+------------------+
1 row in set (0.01 sec)

mysql> SELECT JSON_LENGTH(123.45);
+---------------------+
| JSON_LENGTH(123.45) |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)

mysql> SELECT JSON_LENGTH(CAST('{"i": 0}' AS BINARY));
+-----------------------------------------+
| JSON_LENGTH(CAST('{"i": 0}' AS BINARY)) |
+-----------------------------------------+
|                                       1 |
+-----------------------------------------+
1 row in set (0.01 sec)

4. What is your TiDB version? (Required)

@YangKeao YangKeao added the type/bug The issue is confirmed as a bug. label Feb 11, 2025
@YangKeao YangKeao changed the title JSON_LENGTH shouldn't implicitly cast argument to json JSON_LENGTH, JSON_DEPTH shouldn't implicitly cast argument to json Feb 11, 2025
@YangKeao
Copy link
Member Author

YangKeao commented Feb 11, 2025

Other functions has similar issue, see

SELECT JSON_DEPTH(10);
SELECT JSON_DEPTH(TRUE);
SELECT JSON_INSERT(123, '$.a', 'test');
SELECT JSON_QUOTE(X'7B');
SELECT JSON_QUOTE(BINARY '\0\x1F');
SELECT JSON_QUOTE(0xDEADBEEF);

@YangKeao YangKeao changed the title JSON_LENGTH, JSON_DEPTH shouldn't implicitly cast argument to json JSON_LENGTH, JSON_DEPTH, JSON_INSERT, JSON_QUOTE shouldn't implicitly cast argument to json Feb 11, 2025
@YangKeao YangKeao self-assigned this Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression component/json sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

1 participant