Structure of "Order" table:
objectId text,
subOrders jsonb
structure of Jsonb: array of jsonb objects. eg.
[
{
"className":"SubOrder",
"__type":"Pointer",
"objectId":"tIENf1PCHO"
},
{
"className":"SubOrder",
"__type":"Pointer",
"objectId":"yKVDFEuWx7"
}
]
Structure of "SubOrder" table:
objectId text,
orderitems jsonb
structure of suborder.orderitems jsonb, eg:
[
{
"className":"SubOrderItem",
"__type":"Pointer",
"objectId":"6d1DLrmOTD"
},
{
"className":"SubOrderItem",
"__type":"Pointer",
"objectId":"xK6mR2PDDU"
}
]
I need to join Order.suborders.objectId
with suborder.objectid
AS Order.suborders column is a jsonb array of objects, I am taking the array elements as below.
select jsonb_array_elements("subOrders")->>'objectId'
from "Order"
Then is the problem to join the returned objectId with the Suborder table.