加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

jsonb字段中的PostgreSQL重命名属性

发布时间:2020-12-13 16:30:19 所属栏目:百科 来源:网络整理
导读:在postgresql 9.5中,有没有办法在jsonb字段中重命名属性? 例如: { "nme" : "test" } will be renamed to { "name" : "test"} 在UPDATE中使用 delete (-) and concatenate (||) operators,例如: create table example(id int primary key,js jsonb);insert
在postgresql 9.5中,有没有办法在jsonb字段中重命名属性?

例如:

{ "nme" : "test" } will be renamed to { "name" : "test"}
在UPDATE中使用 delete (-) and concatenate (||) operators,例如:
create table example(id int primary key,js jsonb);
insert into example values
    (1,'{"nme": "test"}'),(2,'{"nme": "second test"}');

update example
set js = js - 'nme' || jsonb_build_object('name',js->'nme')
where js ? 'nme'
returning *;

 id |           js            
----+-------------------------
  1 | {"name": "test"}
  2 | {"name": "second test"}
(2 rows)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读