V
V
Vyacheslav2017-06-16 08:12:31
MySQL
Vyacheslav, 2017-06-16 08:12:31

JSON search in MySQL doesn't want to work?

Hello to all!
I have a mysql 5.7
table with a JSON type items field with data:

{"2464": {"price": "122.97", "status": "10", "quantity": "1", "articleid": "2464", "warehouseid": "3"}, "2469": {"price": "165.61", "status": "10", "quantity": "1", "articleid": "2469", "warehouseid": "3"}, "2522": {"price": "64.18", "status": "10", "quantity": "1", "articleid": "2522", "warehouseid": "3"}, "2524": {"price": "198.73", "status": "10", "quantity": "1", "articleid": "2524", "warehouseid": "3"}}

The question is why I have JSON stored in MySQL - please omit
trying to make the search the most common query:
SELECT * FROM `table` WHERE `items`->'$.*.status' = ':status'

and lo and behold, it doesn't work! :)
moreover, if you put in the condition instead of the sign = sign > then it will work, but not correctly. it will ignore the condition and just output the whole list (`items`->'$.*.status' > ':status')
Tell me what am I doing wrong and how to make it so?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-06-16
@nskarl

SELECT * FROM `table` WHERE `items`->'$.*.status' = :status

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question