pingcap / pingcap/tidb

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

Open
#59,462 1 comment 0 reactions 1 assignee Claimed by @YangKeao View on GitHub
component/expression component/json sig/sql-infra type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.