N
N
Never Ever2021-08-03 19:29:47
MySQL
Never Ever, 2021-08-03 19:29:47

How to do search on MySQL 8 with json type?

There is a json field and the data in it is stored in this way ["a","b","c"]
The data that will come into this field is different, but the result should be returned if there is at least one match in the field.
But I came across such a problem, if you pass in the field (For example, this is in the database ["a","b","c","d"]) such data ['a','b','zxc'] then will not find anything, if ['a','b'] or ['a','b','c'] then

the query itself works as it should

SELECT * FROM table_test WHERE JSON_CONTAINS(field_json, json_array('a','b','ddd'));

As a solution, I thought to generate the request itself a bit like this, but I think such a solution will hit performance hard
SELECT * FROM table_test WHERE JSON_CONTAINS(field_json, json_array('a')) OR  JSON_CONTAINS(field_json, json_array('b')) OR  JSON_CONTAINS(field_json, json_array('ddd'));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maksam07, 2021-08-03
@Target1

https://sqlize.online/?phpses=&sqlses=6abbe647b066...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question