2017-10-11 74 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"}'))) ; 

上述查詢將插入,如果主鍵衝突或約束衝突,則記錄將被更新。

相關問題