I have two tables. Both have a jsonb
column with an array of objects, each containing the key student_id
.
I am trying to build one aggregated JSON value from these jsonb columns.
Lets say table A has four rows and each has jsonb
data like:
[
{
"student_id: 1,
"others element from table A" ...
...
},
{
"student_id: 2,
"others element from table A" ...
...
}
...
]
And table B has holds jsonb
values of the form:
[
{
"student_id": 1,
"others element from table B" ...
},
{
"student_id": 2,
"others element from table B" ...
}
...
]
There is only one row from table B at a time that is to be mapped to multiple rows from table A, all containing different "other_elements"
but with the same "student_id"
value for each object.
My expect result is of the form:
[
{
"student_id": 1,
"others elements from table A" ...
"others elements from table B" ...
},
{
"student_id": 2,
"others elements from table A" ...
"others elements from table B" ...
}
]
Here is a fiddle with sample data demonstrating my case.