繁体   English   中英

我如何在PostgreSQL中使用JSON填充记录进行更新?

[英]How can i use update with json populate record in postgresql?

在Postgresql中,如何将JSON_POPULATE_RECORD用于更新查询?

我们可以将UPDATE查询与JSON_POPULATE_RECORD一起使用。下面是示例表名称作为测试的示例,该示例具有三列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"}'))) ;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM