In UPDATE
use delete (-) and concatenate (||) operators, e.g.:
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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…