Created
February 2, 2015 13:28
-
-
Save Klaasvaak/dba6e72bf03e62de06ea to your computer and use it in GitHub Desktop.
MySQL JSON search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Arrays: | |
WHERE JSON_SEARCH(JSON_EXTRACT('{"categories": [1,2,3]}', 'categories'), "1") != null | |
More info: | |
https://blogs.oracle.com/svetasmirnova/ (usefull blog) | |
http://labs.mysql.com/ (Download page, select MySQL JSON UDFs 0.3.3) | |
https://fosdem.org/2015/schedule/event/moving_to_nosql/ (fosdem talk from Sveta Smirnova - Oracle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment