- 实例1
create table test(id int,name varchar);
insert into test values(1,'a'),(2,'b');
alter table test add col jsonb;
update test set col=format('{"id":"%1$s","name":"%2$s"}',id, name)::jsonb;
- 结果:
- 实例2
create table test2(id int,name varchar);
insert into test2 values(1,'a'),(2,'b');
alter table test2 add col json;
update test set col=format('{"id":"%1$s","name":"%2$s"}',id, name)::json;
- 结果:
参考:
参考博客1