Chaining JSON_EXTRACT with CAST or STR_TO_DATE fails

依然范特西╮ 提交于 2019-12-05 05:53:28

You have to use JSON_UNQUOTE

select CAST( JSON_UNQUOTE( JSON_EXTRACT(data, "$.new_time")) as DATETIME) from analytics_calendaranalytics limit 10;

Would work. I am saying would because you haven't provided sample data. I tried as follows:

select @js := JSON_OBJECT('new_time',"2016-09-30T04:00:00+00:00"  );

select CAST(JSON_UNQUOTE(JSON_EXTRACT(@js,'$.new_time')) as DATETIME);

The following query also works

 select STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(@js,'$.new_time')) ,"%Y-%m-%d");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!