你好,这是我的 json
{
"name":'test',
"options": {
"Repartition": "Active",
"Satellite": "No"
}
}
我想用“s”重命名“卫星”中的“卫星”,但我没有成功。
我试过 :
UPDATE "Liaison" set content = content->>'options' - 'Satellite' || jsonb_build_object('Satellites', content->>'options'->'Satellite') where id =52056
但我有一个错误:
运算符不唯一:未知 - 未知
这是我的桌子:
ID | content
---------------------
52056 | the json
->>
返回元素为text
,因此您失去了对其应用 JSON 运算符的能力。你需要使用->
以 JSON 形式返回(子)元素并使用jsonb_set()
改变options
内容中的元素:
UPDATE "Liaison"
set content = jsonb_set(content, array['options'],
(content -> 'options') - 'Satellite'||
jsonb_build_object('Satellites', content -> 'options' -> 'Satellite'))
where id = 52056;
The -
然而,运算符仅适用于 JSONB,不适用于 JSON。因此,如果您的列确实是 JSON,则需要将中间结果转换为 JSONB。
网上例子:http://rextester.com/EXTS36112
另一种选择是使用jsonb_set()
创建一个新元素并#-
删除旧的。
UPDATE liaison
set content = jsonb_set(
content,
array['options','Satellites'],
(content #> array['options','Satellite']), true
) #- array['options','Satellite']
where id = 52056;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)