更新Postgresql中JSON元素的值

问题描述 投票:1回答:1

我有一个具有以下表结构的表:

create table instances(id bigint, createdate timestamp, createdby bingint, lastmodifieddate timestamp, lastmodifiedby bigint, context text)

字段context包含JSON数据,即

insert into instances values (1, '2020-06-01 22:10:04', 20112,'2020-06-01 22:10:04',20112, '{"id":1,"details":[{"binduserid":90182}]}')

我需要使用postgres查询将JSON元素binduserid的所有值替换为值90182。

我已经通过使用REPLACE功能实现了这一点:

update instances set context = replace(context, '"binduserid":90182','"binduserid":1000619');

还有其他使用Postgres JSON函数的方法吗?>

我有一个具有以下表结构的表:创建表实例(id bigint,createdate时间戳,bingint创建,lastmodifieddate时间戳,bigint,bigint,上下文文本)字段上下文...

postgresql postgresql-9.5
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.