【发布时间】:2020-11-04 14:04:52
【问题描述】:
data 列是 jsonb
SELECT
json_agg(shop_order)
FROM (
SELECT data from shop_order
WHERE data->'contacts'->'customer'->>'phone' LIKE '%1234567%' LIMIT 3 OFFSET 3
) shop_order
这里的结果是数组:
[
{
"data": {
"id": 211111,
"cartCount": 4,
"created_at": "2020-10-28T12:58:33.387Z",
"modified_at": "2020-10-28T12:58:33.387Z"
}
}
]
很好。但是...我需要隐藏节点 data。
结果必须是
[
{
"id": 211111,
"cartCount": 4,
"created_at": "2020-10-28T12:58:33.387Z",
"modified_at": "2020-10-28T12:58:33.387Z"
}
]
有可能吗?
【问题讨论】:
-
select jsonb_agg(to_jsonb(data)) from shop_order ...呢? -
@a_horse_with_no_name 是的,这很有帮助。谢谢
标签: postgresql-9.5