Created
January 8, 2015 15:11
-
-
Save andergmartins/184fa7303a413a95249d to your computer and use it in GitHub Desktop.
Extract data from JSON string inside a MySQL field. In this case, extract metadesc and page title from the menu params
This file contains 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
SELECT m.id, m.title, | |
@tmp_search := '"menu-meta_description":"' AS tmp_search, | |
@tmp_search_len := LENGTH(@tmp_search) AS tmp_search_len, | |
@start := LOCATE(@tmp_search, m.params) AS tmp_start, | |
@end := LOCATE('"', m.params, @start + @tmp_search_len) AS tmp_end, | |
SUBSTRING(m.params, @start + @tmp_search_len, @end - @start - @tmp_search_len) AS metadesc, | |
@tmp_search := '"page_title":"' AS tmp_search, | |
@tmp_search_len := LENGTH(@tmp_search) AS tmp_search_len, | |
@start := LOCATE(@tmp_search, m.params) AS tmp_start, | |
@end := LOCATE('"', m.params, @start + @tmp_search_len) AS tmp_end, | |
SUBSTRING(m.params, @start + @tmp_search_len, @end - @start - @tmp_search_len) AS metatitle | |
FROM j_menu AS m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment