1

I have a column which has json type arrays like

row1: ["abc", 10, null, true, false]
row2: ["def", 10, null, true, false]

How can i use where clause to find "abc" contained rows? My json arrays has no key. They only have values.

select * from myTable where JSON_SEARCH(myColumn,"all","abc")

returns 0 rows

1 Answer 1

1

You can use MySQL JSON search function JSON_CONTAINS():

where json_contains(myColumn, '"abc"')
Sign up to request clarification or add additional context in comments.

4 Comments

it returns Error Code: 3141. Invalid JSON text in argument 2 to function json_contains: "Invalid value." at position 0.
It requires double quotes like '"abc"'. When I try like that, it works
@hakiko: indeed, thanks for spotting that. I fixed my answer accordingly.
If you are using the multi-value indexes then you can use functions like MEMBER OF see dev.mysql.com/doc/refman/8.0/en/json-search-functions.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.