开发者社区> 问答> 正文

postgres9.4 更新问题,如何修改name=timeSampleRPM 的interval的值呢?

drop table if exists the_table cascade;

create table the_table (id integer, the_column jsonb);
insert into the_table values (1, '{"key1": {"key2": { "key3": "value"}}}'::jsonb);
insert into the_table values (2, '[{"name": "timeSampleRPM", "interval": 30, "maxRegister": 18, "minRegister": 18}, {"name": "timeSampleSpeed", "interval": 30, "maxRegister": 19, "minRegister": 19}, {"name": "timeSampleCurON", "interval": 30, "maxRegister": 22, "minRegister": 22}, {"name": "timeSampleLED", "interval": 30, "maxRegister": 20, "minRegister": 20}, {"name": "timeSampleNormal", "interval": 30, "maxRegister": 0, "minRegister": 0}]');

update the_table 
  set the_column =  jsonb_set(the_column,'{1,interval}','120',false)
where id =2;

--如何取到对应"name"="timeSampleRPM" 的index '{1,interval}' 1的index

select id, jsonb_pretty(the_column)
from the_table;

展开
收起
梨儿 2019-01-28 11:28:56 2053 0
1 条回答
写回答
取消 提交回答
问答地址:
问答排行榜
最热
最新

相关电子书

更多
对 2000 多亿条数据做一次 group by 需要多久? 立即下载
对2000多亿条数据做一次Group By 需要多久 立即下载
低代码开发师(初级)实战教程 立即下载