Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JSON extract where data has no key

Tags:

database

mysql

My data:

 ["2016-04-21", "2016-04-22"] 

My Query:

select * from applications WHERE JSON_CONTAINS("date", "$");

My json data do not have keys, show how I can use JSON_CONTAINS here?

like image 615
Suman kumar panda Avatar asked May 15 '26 03:05

Suman kumar panda


1 Answers

In case you want to find a date value in your JSON data you can use the following using JSON_SEARCH instead:

SELECT * 
FROM applications 
WHERE NOT JSON_SEARCH(col_json, 'one', '2016-04-22') IS NULL;

demo on dbfiddle.uk


Why you can't use JSON_CONTAINS?

To search a specific date value in your JSON data you need to use a wildcard (*). This isn't allowed on the JSON_CONTAINS path argument:

An error occurs if target or candidate is not a valid JSON document, or if the path argument is not a valid path expression or contains a * or ** wildcard.

like image 133
Sebastian Brosch Avatar answered May 16 '26 16:05

Sebastian Brosch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!