" Order"的结构表:
objectId text,
subOrders jsonb
Jsonb的结构:jsonb对象的数组。例如
[
{
"className":"SubOrder",
"__type":"Pointer",
"objectId":"tIENf1PCHO"
},
{
"className":"SubOrder",
"__type":"Pointer",
"objectId":"yKVDFEuWx7"
}
]
" SubOrder"的结构表:
objectId text,
orderitems jsonb
suborder.orderitems jsonb的结构,例如:
[
{
"className":"SubOrderItem",
"__type":"Pointer",
"objectId":"6d1DLrmOTD"
},
{
"className":"SubOrderItem",
"__type":"Pointer",
"objectId":"xK6mR2PDDU"
}
]
我需要与Order.suborders.objectId
suborder.objectid
AS Order.suborders列是一个jsonb对象数组,我将采用如下的数组元素。
select jsonb_array_elements("subOrders")->>'objectId'
from "Order"
然后是将返回的objectId与Suborder表连接的问题。
答案 0 :(得分:0)
答案 1 :(得分:0)
将函数调用放入FROM
子句中,稍后取消引用JSON对象的实际字段。
select o.object_id, so.*
from "Order" o
cross join lateral jsonb_array_elements(sub_orders) j(suborder)
join sub_order so on so.object_id = j.suborder ->> 'objectId'