Skip to content

Instantly share code, notes, and snippets.

Created February 2, 2015 13:28
What would you like to do?
MySQL JSON search
Instead of using regexp like so:
ancestors column would be something like: {"category": 1}
WHERE `ancestors` REGEXP '(.*\"category\":\"1\")'
Use the JSON functions:
WHERE JSON_EXTRACT(`ancestors`, 'category') = 1
WHERE JSON_SEARCH(JSON_EXTRACT('{"categories": [1,2,3]}', 'categories'), "1") != null
More info: (usefull blog) (Download page, select MySQL JSON UDFs 0.3.3) (fosdem talk from Sveta Smirnova - Oracle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment