Say, I have the following postgres table,
> select * from t;
+----+---------+-----------+---------+---------+
| id | a | b | c | d |
+----+---------+-----------+---------+---------+
| 1 | value_a | value_b | value_c | value_d |
+----+---------+-----------+---------+---------+
...
+----+---------+-----------+---------+---------+
|... | ... | ... | ... | ... |
+----+---------+-----------+---------+---------+
Now I want to create a view from this table which is capable of storing data of following format having nested json text.
And this should be grouped by id column.
{
"id": 1,
"a": "A",
"x":"{\"k1\":\"value_b\",\"k2\":\"{\"k21\":\"value_c\",\"k22\":\"value_d\"}\"}"
}
I have no idea how can I achieve this. Anyone there to write me a postgres sql query for this.