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

Using JSON_TYPE on non-JSON values should return an error #54029

Closed
dveeden opened this issue Jun 14, 2024 · 1 comment · Fixed by #54145
Closed

Using JSON_TYPE on non-JSON values should return an error #54029

dveeden opened this issue Jun 14, 2024 · 1 comment · Fixed by #54145
Assignees
Labels
component/json severity/minor sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@dveeden
Copy link
Contributor

dveeden commented Jun 14, 2024

Bug Report

1. Minimal reproduce step (Required)

CREATE TABLE t1(id INT PRIMARY KEY, d1 DATE, d2 DATETIME, t1 TIME, t2 TIMESTAMP, b1 BIT, b2 BINARY);
INSERT INTO t1 VALUES (1, '2024-06-14', '2024-06-14 09:37:00', '09:37:00', '2024-06-14 09:37:00', b'0', 0x41);
SELECT JSON_TYPE(d1),JSON_TYPE(d2),JSON_TYPE(t1),JSON_TYPE(t2),JSON_TYPE(b1),JSON_TYPE(b2) FROM t1;

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

mysql-8.4.0> CREATE TABLE t1(id INT PRIMARY KEY, d1 DATE, d2 DATETIME, t1 TIME, t2 TIMESTAMP, b1 BIT, b2 BINARY);
Query OK, 0 rows affected (0.02 sec)

mysql-8.4.0> INSERT INTO t1 VALUES (1, '2024-06-14', '2024-06-14 09:37:00', '09:37:00', '2024-06-14 09:37:00', b'0', 0x41);
Query OK, 1 row affected (0.01 sec)

mysql-8.4.0> SELECT JSON_TYPE(d1),JSON_TYPE(d2),JSON_TYPE(t1),JSON_TYPE(t2),JSON_TYPE(b1),JSON_TYPE(b2) FROM t1;
ERROR 3146 (22032): Invalid data type for JSON data in argument 1 to function json_type; a JSON string or JSON type is required.

3. What did you see instead (Required)

mysql-8.0.11-TiDB-v8.1.0> CREATE TABLE t1(id INT PRIMARY KEY, d1 DATE, d2 DATETIME, t1 TIME, t2 TIMESTAMP, b1 BIT, b2 BINARY);
Query OK, 0 rows affected (0.11 sec)

mysql-8.0.11-TiDB-v8.1.0> INSERT INTO t1 VALUES (1, '2024-06-14', '2024-06-14 09:37:00', '09:37:00', '2024-06-14 09:37:00', b'0', 0x41);
Query OK, 1 row affected (0.01 sec)

mysql-8.0.11-TiDB-v8.1.0> SELECT JSON_TYPE(d1),JSON_TYPE(d2),JSON_TYPE(t1),JSON_TYPE(t2),JSON_TYPE(b1),JSON_TYPE(b2) FROM t1;
+---------------+---------------+---------------+---------------+------------------+---------------+
| JSON_TYPE(d1) | JSON_TYPE(d2) | JSON_TYPE(t1) | JSON_TYPE(t2) | JSON_TYPE(b1)    | JSON_TYPE(b2) |
+---------------+---------------+---------------+---------------+------------------+---------------+
| DATE          | DATETIME      | TIME          | DATETIME      | UNSIGNED INTEGER | BLOB          |
+---------------+---------------+---------------+---------------+------------------+---------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

Release Version: v8.1.0
Edition: Community
Git Commit Hash: 945d07c5d5c7a1ae212f6013adfb187f2de24b23
Git Branch: HEAD
UTC Build Time: 2024-05-21 03:51:57
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
@dveeden dveeden added type/bug The issue is confirmed as a bug. component/json severity/minor labels Jun 14, 2024
@jebter jebter added the sig/sql-infra SIG: SQL Infra label Jun 18, 2024
@YangKeao YangKeao self-assigned this Jun 20, 2024
@YangKeao
Copy link
Member

This issue actually has two bugs:

  1. TiDB didn't verify type of args for json_type.
  2. TiDB didn't verify charset of args for many json related functions ('binary' is not allowed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/json severity/minor sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants