PG与json类型

  • 实例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

原文地址:https://www.cnblogs.com/yldf/p/11899941.html