我正在处理postgresql JSONB
列,我想在Array
中更新Array
,这里是我的json,看起来像这样
[
{
"name": "Arjun",
"artList": [
{
"id": 34,
"category": "Sports",
"names": [
{
"id": 11,
"label": "Cricket"
},
{
"id": 12,
"label": "Football"
},
{
"id": 13,
"label": "Hockey"
}
]
},
{
"id": 35,
"category": "Entertainment",
"names": [
{
"id": 101,
"label": "Ancor"
},
{
"id": 102,
"label": "Comdey"
},
{
"id": 103,
"label": "Singer"
}
]
}
]
}
]
字符串
要求是从Sports
类别的artList
中删除Cricket
,其中名称为Arjun。
这就是我到目前为止所尝试的,但它不起作用。
UPDATE usr
SET art = s.json_array
FROM (
SELECT
jsonb_agg(
elems
) as json_array
FROM
usr p,
jsonb_array_elements(p.art) elems where p.name ='Sports' and elems->>'label'<>'Cricket'
) s where name ='Arjun'
型
1条答案
按热度按时间ni65a41a1#
使用多个嵌套
jsonb_build_object
调用:字符串
See fiddle