2017-10-11 34 views

回答

1

我们可以使用带有JSON_POPULATE_RECORD的UPDATE查询下面是样本表名称作为测试的示例,它有三列a,b,c,数据类型字符不一样。

update test set("a","b","c")=((select a,b,c from json_populate_record(NULL::test,'{"a":"first column","b":"second column","c":"third column"}'))) 

您还可以使用UPSERT与此查询。

insert into test select * from json_populate_record(NULL::test, '{"a":"first column","b":"column","c":"column"}') ON CONFLICT ON CONSTRAINT a_PKey DO UPDATE SET("a","b","c")=((select a,b,c from json_populate_record(NULL::test,'{"a":"first column","b":"second column","c":"third column"}'))) ; 

上述查询将插入,如果主键冲突或约束冲突,则记录将被更新。

相关问题