I have a table in a mysql database which looks like this:
ID CONFIG
0 276 {"pos":[{"type":"geo...
1 349 {"pos":[{"type":"geo...
2 378 {"pos":[{"type":"geo...
3 381 {"pos":[{"type":"geo...
4 385 {"pos":[{"type":"geo...
where the elements in the CONFIG column all have the form:
{"posit":[{"type":"geo_f","priority":1,"validity":0},{"type":"geo_m","priority":2,"validity":0},{"type":"geo_i","priority":3,"validity":0},{"type":"geo_c","priority":4,"validity":0}]}
Now, I know how to "explode" this table for the first level:
SELECT *,
CONFIG ->'$.posit' as Position
FROM mytable;
which return
ID CONFIG Position
0 276 {"pos":[{"type":"geo... [{"type":"geo...
1 349 {"pos":[{"type":"geo... [{"type":"geo...
2 378 {"pos":[{"type":"geo... [{"type":"geo...
3 381 {"pos":[{"type":"geo... [{"type":"geo...
4 385 {"pos":[{"type":"geo... [{"type":"geo...
where the elements of Position are lists of json-strings:
[{"type":"geo_f","priority":1,"validity":0},{"type":"geo_m","priority":2,"validity":0},{"type":"geo_i","priority":3,"validity":0},{"type":"geo_c","priority":4,"validity":0}]
But, I do not have a clue of how to take the next step to "explode" the elements of Position. The resulting table should have:
- 4 times the number of rows as the original table since there are four json-strings. I.e., 4 rows for each
ID. - The addition of columns
type, priority, validity.
I tried different way to extract this information:
SELECT *,
CONFIG ->'$.posit' as Position,
Position ->>'$.type' as Type
FROM mytable
but that evidently failed.
Any help would be greatly appreciated!