在PostgreSQL中更新jsonb数据中的多个值 [英] Update multiple values in a jsonb data in PostgreSQL

查看:1289
本文介绍了在PostgreSQL中更新jsonb数据中的多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在表设置"中更新jsonb数据(列->用户) 我的jsonb数据就像

I need to update a jsonb data(column->users) in my table 'settings' My jsonb data is like

'{
    "Email": "aaaa",
    "UserId": "49",
    "Created": "11/13/2016",
    "EntityId": "1",
    "IsActive": "False",
    "Modified": "11/13/2016",
    "Username": "aa"
}' 

在这个json字符串中,我需要一起更新Email,IsActive,Username. 我试过下面的更新查询,它的工作正常.但这是对单个值的更新.

In this json string I need to update Email,IsActive,Username together. I tried the below update query,its working fine. But that is for a single value updation.

UPDATE settings 
SET users = jsonb_set(users, '{Email}', '"aa"') 
WHERE users @> '{"UserId":"49"}';

如何更新多个值?我正在使用Postgres 9.5.

How to update for multiple value updation? I am using postgres 9.5.

推荐答案

使用串联运算符:

UPDATE settings 
SET users = users || '{"Email": "new email", "IsActive": "True", "Username": "new username"}'
WHERE users @> '{"UserId":"49"}';

这篇关于在PostgreSQL中更新jsonb数据中的多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆