【发布时间】:2021-10-06 06:41:18
【问题描述】:
我的表的foods 列中有以下 json 数据:
[
{
"name": "Pasta",
"price": 45.8,
"comments": {
"promo": true,
"special": true
}
},
{
"name": "Risotto",
"price": 31.4,
},
{
"name": "Pizza",
"price": 64.9,
"comments": {
"promo": true,
"special": true
}
},
{
"name": "Hamburguer",
"price": 14.9,
"comments": {
"combo": true
}
},
]
我想删除所有promo 键,看起来像这样。
[
{
"name": "Pasta",
"price": 45.8,
"comments": {
"special": true
}
},
{
"name": "Risotto",
"price": 31.4,
},
{
"name": "Pizza",
"price": 64.9,
"comments": {
"special": true
}
},
{
"name": "Hamburguer",
"price": 14.9,
"comments": {
"combo": true
}
},
]
此数据可能没有多大意义,因为它是一个示例,用于显示我正在尝试解决的案例,但有更多数据,我需要删除某些对象中存在的键(不是全部,如示例中所示)位于 jsonb 数组中。 我怎样才能表现得最好?我使用的是 PostgreSQL 版本 12,所以最好使用 jsonb 函数。
【问题讨论】:
-
使用适当的规范化数据模型会很容易。
标签: postgresql jsonb