3
postgresql 9.5では、jsonbフィールドの属性の名前を変更する方法はありますか?例えばjsonbフィールドのPostgreSQLリネーム属性
:UPDATE
使用delete (-) and concatenate (||) operatorsで
{ "nme" : "test" } will be renamed to { "name" : "test"}
postgresql 9.5では、jsonbフィールドの属性の名前を変更する方法はありますか?例えばjsonbフィールドのPostgreSQLリネーム属性
:UPDATE
使用delete (-) and concatenate (||) operatorsで
{ "nme" : "test" } will be renamed to { "name" : "test"}
、例えば:
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')
returning *;
id | js
----+-------------------------
1 | {"name": "test"}
2 | {"name": "second test"}
(2 rows)