I have the following jsonb :
[
[
{
"id": 51003,
"user_id": 4554,
"sg_id": 143353
}, {
"id": 51004,
"user_id": 4555,
"sg_id": 143353
}
],
[
{
"id": 51005,
"user_id": 4555,
"sg_id": 143354
}
]
]
And i’m trying to reduce it by removing the nested array level. I expect something like :
[
{
"id": 51003,
"user_id": 4554,
"sg_id": 143353
}, {
"id": 51004,
"user_id": 4555,
"sg_id": 143353
}, {
"id": 51005,
"user_id": 4555,
"sg_id": 143354
}
]
I cannot figure out how to solve with with postgres and would appreciate any help. Cheers !
2
Answers
->0
to access to the first element of the array which contains two objects,|| to concat the object of the last array into the array.
::jsonb
is to cast our varchar into jsonResult :
Demo here