我正在使用 postgresql 9.4
我在表中有一个 json 列,它包含以下值:
"{
"title" : "risk",
"name" : "David"
}"
我必须执行两个功能
- 将 name 值更新为“John”
- 插入 "city": "paris"
我的最终值应该在我的表列中
"{
"title" : "risk",
"name" : "John",
"city" : "paris"
}"
基本上,我想更新和插入这个 json 列的查询,我不能将数据库更改为更高版本
最佳答案
类似于:
update table
set jbcolumn = json_build_object('title',jbcolumn->>'title','name','John','city','Paris') where bcolumn->>'name' = 'David
在 postgres 9.4 中
https://www.postgresql.org/docs/9.4/static/functions-json.html
json_build_object(VARIADIC "any")
关于sql - 在 postgresql JSON 中添加列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47220726/