我用
select to_json(host) from host where id=3
从我的postgreSQL数据库查询数据结果如下:
{"id":3,"project_id":1,"name":"a","mac":"abc","info":"x"}
在我的应用程序中更改数据后,我想更新表。
这样做有“json”吗?没有做像
这样的普通更新update host set project_id=1, name='a', mac='abc',info='x' where id=1;
答案 0 :(得分:4)
update from
clause
update host
set
(project_id, name, mac, info) =
(j.project_id, j.name, j.mac, j.info)
from jsonb_populate_record ( null::host,
'{"id":1,"project_id":1,"name":"a","mac":"abc","info":"x"}'::jsonb
) j
where host.id = j.id