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

Invalid JSON value for CAST to DATE/TIME/DATETIME/TIMESTAMP from column json_extract for virtual column #13722

Closed
wjhuang2016 opened this issue Nov 25, 2019 · 1 comment
Labels

Comments

@wjhuang2016
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
create table t1 (a timestamp as (json_extract(k,'$.a')), b datetime as (json_extract(k, '$.a')) stored, k json);
insert into t1 set k='{\"a\":\"2018-09-28 12:59:51\"}';
select * from t1;
  1. What did you expect to see?
    Get the data.

  2. What did you see instead?

mysql> select * from t1;
+---+---------------------+------------------------------+
| a | b                   | k                            |
+---+---------------------+------------------------------+
| NULL | 2018-09-28 12:59:51 | {"a": "2018-09-28 12:59:51"} |
+---+---------------------+------------------------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+---------------------------------------------------+
| Level   | Code | Message                                           |
+---------+------+---------------------------------------------------+
| Warning | 1105 | cannot convert datum from json to type timestamp. |
+---------+------+---------------------------------------------------+
1 row in set (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

master

@ghost
Copy link

ghost commented Jul 20, 2020

Confirming this bug is fixed in master:

drop table if exists t1;
create table t1 (a timestamp as (json_extract(k,'$.a')), b datetime as (json_extract(k, '$.a')) stored, k json);
insert into t1 set k='{\"a\":\"2018-09-28 12:59:51\"}';
select * from t1;

..

mysql> select * from t1;
+---------------------+---------------------+------------------------------+
| a                   | b                   | k                            |
+---------------------+---------------------+------------------------------+
| 2018-09-28 12:59:51 | 2018-09-28 12:59:51 | {"a": "2018-09-28 12:59:51"} |
+---------------------+---------------------+------------------------------+
1 row in set (0.00 sec)

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-798-gd941ff5cc
Edition: Community
Git Commit Hash: d941ff5cc8b4babf9dcfdd91b66a5c53b798c122
Git Branch: master
UTC Build Time: 2020-07-18 05:54:02
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

Interestingly, this is invalid in MySQL 5.7 but works in MySQL 8.0:

mysql [localhost:5731] {msandbox} (test) > insert into t1 set k='{\"a\":\"2018-09-28 12:59:51\"}';
ERROR 3156 (22018): Invalid JSON value for CAST to DATE/TIME/DATETIME/TIMESTAMP from column json_extract at row 1

mysql [localhost:8021] {msandbox} (test) > insert into t1 set k='{\"a\":\"2018-09-28 12:59:51\"}';
Query OK, 1 row affected (0.00 sec)

mysql [localhost:8021] {msandbox} (test) > select * from t1;
+---------------------+---------------------+------------------------------+
| a                   | b                   | k                            |
+---------------------+---------------------+------------------------------+
| 2018-09-28 12:59:51 | 2018-09-28 12:59:51 | {"a": "2018-09-28 12:59:51"} |
+---------------------+---------------------+------------------------------+
1 row in set (0.00 sec)

I am going to close this issue now. Thanks!

@ghost ghost closed this as completed Jul 20, 2020
@ghost ghost unassigned Deardrops Jul 20, 2020
@ghost ghost added the component/json label Jul 25, 2020
@ghost ghost added the component/expression label Jul 25, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants