I have a MySQL 5.7 table that looks like this:
id | meta |
---|---|
1 | null |
2 | {"grant_ids": [5, 7]} |
I’d like to query for rows that have the presence of the value of 5 in meta-> grant_ids.
I tried
select * from content.banners where meta->>"$.grant_ids" in (5);
but not working. I don’t think in
is supported but any ideas how to achieve this query?
2
Answers
You can write it like this, using the JSON function of SQL:
DBFiddle
JSON_EXTRACT() will only return the JSON array at the path you give, and an array isn’t the scalar value 5. Unquoting a JSON array with the
->>
operator has no effect; an "unquoted" JSON array is the exact same array.