The database I'm working with stores JSON records in LONGTEXT data types. I want to be able to select records based on JSON data. Here are some sample data:
{ "12f9cb0a-2218-4590-a05d-c1ffab00f693": { "0": { "value": "test" } }, "4d1dfd2e-7bc1-4303-9c8c-90856e918bb9": { "item": { "0": "11" } } }
So, I want to select data containing "4d1dfd2e-7bc1-4303-9c8c-90856e918bb9": {"item": {"0": "11"}} , filtering out spaces (tabs, spaces, newlines) using the REGEXP function I tried this to no avail:
SELECT * FROM my_table WHERE (elements REGEXP BINARY '"4d1dfd2e-7bc1-4303-9c8c-90856e918bb9":\s*{\s*"item":\s*{\s*"0":\s*"11"\s*}\s*}');
The regex test works using Rubular and Regexpal.com, but MYSQL is not like the \ s * expression. Does anyone have a better solution for this?
Tommy plummer
source share