I would like to query data from MySQL database from JSON type column.
I got a query which works and return data from JSON field:
SELECT
readouts->"$.temperature_sensor_1.readTimestamp"
FROM
`readouts_store`
WHERE
`readout_id`=75898
it returns:
"2018-02-04 20:11:53"
But to limit the selected data by date I need it to something like this:
SELECT
readouts->"$.temperature_sensor_1.value"
FROM
`readouts_store`
WHERE
`application_id`=1
AND
readouts->"$.temperature_sensor_1.readTimestamp", '%Y-%m-%d %H:%i:%s' BETWEEN '2018-02-03' AND '2018-02-05'
It doesn't work so I think it is expected that I convert readouts->"$.temperature_sensor_1.readTimestamp" into DATE type like this:
SELECT
readouts->"$.temperature_sensor_1.value"
FROM
`readouts_store`
WHERE
`application_id`=1
AND
STR_TO_DATE(readouts->"$.temperature_sensor_1.readTimestamp", '%Y-%m-%d %H:%i:%s') BETWEEN '2018-02-03' AND '2018-02-05'
unfortunately it doesn't work because STR_TO_DATE() returns NULL:
SELECT
STR_TO_DATE(readouts->"$.temperature_sensor_1.readTimestamp", '%Y-%m-%d %H:%i:%s')
FROM
readouts_store
WHERE
`readout_id`=75898
Instead of STR_TO_DATE() I also tried DATE() and CONVERT("", DATE) but the result is the same.
Is such functionality not supported in MySQL? I cannot find any reference in documentation covering this.