Skip to content
Advertisement

Chaining JSON_EXTRACT with CAST or STR_TO_DATE fails

I’m trying to extract a datetime from a JSONFIELD “data” in MySQL.

If I do a simple JSON_EXTRACT however, the return field type is a JSON.

I want to convert this to a MySQL DATETIME. But if I chain JSON_EXTRACT and STR_TO_DATETIME, I get all NULL values:

Likewise, a CAST as DATETIME also fails:

Both these commands work when I start with the string value:

Would appreciate any help in resolving this!

Advertisement

Answer

You have to use JSON_UNQUOTE

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

The following query also works

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement