Skip to content

Update JSON type column from JSON 'null' to database NULL dost not work #37852

@Mini256

Description

@Mini256

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `t1` (
  `id` int(11) NOT NULL,
  `json` json DEFAULT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
mysql> INSERT INTO t1 VALUES(1, 'null');
Query OK, 1 row affected (0.01 sec)

mysql> SELECT IFNULL(json, 'it is db null') FROM t1;
+-------------------------------+
| IFNULL(json, 'it is db null') |
+-------------------------------+
| null                          |
+-------------------------------+
1 row in set (0.01 sec)

mysql> UPDATE `t1` SET json = null WHERE id = 1;
Query OK, 0 rows affected (0.01 sec)
Rows matched: 1  Changed: 0  Warnings: 0

mysql> SELECT IFNULL(json, 'it is db null') FROM t1;
+-------------------------------+
| IFNULL(json, 'it is db null') |
+-------------------------------+
| null                          |
+-------------------------------+
1 row in set (0.00 sec)

If you change from other values to NULL, it works.

mysql> UPDATE `t1` SET json = '{}' WHERE id = 1;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> UPDATE `t1` SET json = null WHERE id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> SELECT IFNULL(json, 'it is db null') FROM t1;
+-------------------------------+
| IFNULL(json, 'it is db null') |
+-------------------------------+
| it is db null                 |
+-------------------------------+
1 row in set (0.00 sec)

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

Should work when updating NULL value for the JSON type column with 'null' value.

3. What did you see instead (Required)

Update JSON type column from JSON 'null' to database NULL does not work, as the result Changed: 0.

4. What is your TiDB version? (Required)

mysql> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.2.0
Edition: Community
Git Commit Hash: daf2b17cdfe30c02ce282361009fb5bdb05f2b0e
Git Branch: heads/refs/tags/v6.2.0
UTC Build Time: 2022-08-22 13:38:40
GoVersion: go1.18.5
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv
1 row in set (0.00 sec)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions