Using postgresql,
This is the table I have:
id | json
1 | [{"key":"abc", "value":"123"}, {"key":"def", "value":"456"}]
2 | [{"key":"def", "value":"789"}, {"key":"fgh", "value":"456"}]
I'd like to turn it into this
id | abc | def | fgh
1 | 123 | 456 | NULL
2 | NULL | 789 | 456
I think the answer lies in between using json_array_elements, array_agg and some form of nested subquery.
I'm a little confused as to how to apply them in this scenario.
What query can I write for this?