-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
ddl: column type change will use default value as converted one for a invalid old json string #25028
Comments
/assign |
Ref: https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html
that's weird. I think it's a bug both exits in mysql and tidb., maybe we should not adapt it until mysql fix it. In my opinion, It's the same thing if we But the result of mysql> select json_valid('null'), json_valid(null), json_valid('"null"'), json_type('null'), json_type(null), json_type('"null"');
+--------------------+------------------+----------------------+-------------------+-----------------+---------------------+
| json_valid('null') | json_valid(null) | json_valid('"null"') | json_type('null') | json_type(null) | json_type('"null"') |
+--------------------+------------------+----------------------+-------------------+-----------------+---------------------+
| 1 | NULL | 1 | NULL | NULL | STRING |
+--------------------+------------------+----------------------+-------------------+-----------------+---------------------+
1 row in set (0.00 sec)
mysql>select isnull('null'), isnull(null), isnull('"null"');
+----------------+--------------+------------------+
| isnull('null') | isnull(null) | isnull('"null"') |
+----------------+--------------+------------------+
| 0 | 1 | 0 |
+----------------+--------------+------------------+
1 row in set (0.00 sec) Given all that, I think we can keep it until it becomes more clear. @AilinKid @djshow832 |
I think it still makes sense for MySQL. mysql> create table t(j json);
Query OK, 0 rows affected (0.07 sec)
mysql> insert t value('null'), (NULL);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select isnull(j) from t;
+-----------+
| isnull(j) |
+-----------+
| 0 |
| 1 |
+-----------+
2 rows in set (0.00 sec)
MySQL and TiDB act the same for the above statements, but here is the difference: In MySQL: mysql> select cast(j as unsigned) from t;
+---------------------+
| cast(j as unsigned) |
+---------------------+
| 0 |
| NULL |
+---------------------+
2 rows in set, 1 warning (0.01 sec)
mysql> show warnings;
+---------+------+---------------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------------+
| Warning | 3156 | Invalid JSON value for CAST to INTEGER from column j at row 1 |
+---------+------+---------------------------------------------------------------+
1 row in set (0.00 sec) In TiDB: mysql> select cast(j as unsigned) from t;
+---------------------+
| cast(j as unsigned) |
+---------------------+
| 0 |
| NULL |
+---------------------+
2 rows in set (0.01 sec) TiDB casts the value |
Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label. |
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
3. What did you see instead (Required)
TiDB
4. What is your TiDB version? (Required)
master
The text was updated successfully, but these errors were encountered: