Here is a sample of the data that I am working with:
id | col1 | col2
1 | Name1 | {'spec_details': {'spec_values': [{'name':'A','value':2}, {'name': 'B', 'value': 5}, {'name': 'C', 'value': 6}], 'spec_id': 'ASVSDAS'}, 'channel': 'channel1'}
2 | Name2 | {'spec_details': {'spec_values': [{'name':'A','value':9}, {'name': 'B', 'value': 1}, {'name': 'D', 'value': 8}], 'spec_id': 'QWSAASS'}, 'channel': 'channel1'}
In the above case, I want to convert the specific spec_values present within col2 into seperate columns. So, the output I am looking at is:
id | col1 | A | B | C | D | spec_id
1 | Name1 | 2 | 5 | 6 | | ASVSDAS
2 | Name2 | 9 | 1 | | 8 | QWSAASS
How can I do this? I know I can get the values of spec_id by using ->> So, it becomes col2->>'spec_id' for getting spec_id values. In case of spec_values, I know I can get specific values at index as col2->'spec_values'[0], and col2->'spec_values'[1] etc. Further, can get specific name etc as col2->'spec_values'[0]->>'name'
However, am looking to have it as a column instead. Can someone please help?
nameand print its related value in the select query. However, since I used distinct to get all uniquenamevalues, it is difficult to convert it. Checking usingWITHif can modify the sql by having cols.