开发者社区> 问答> 正文

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

梨儿 2019-01-28 11:28:56 365
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;
分享到
取消 提交回答
全部回答(1)
+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

推荐文章