我在PostgreSQL数据库中有json数据类型的列。我想连续更新整个json。请提出我该怎么做。我尝试使用更新sql函数,但是没有用。
UPDATE "WORKER_DATA"
SET raw_data = '{"dbInfo":{"id":"8","lifeTime":"DELETED"}}'
WHERE id = '8';
我想更新整个json,所以我该怎么做?我在数据库中有一个json
{"dbInfo":{"id":"8","lifeTime":"ACTIVE","version":"3"}}
我想更新整个json
{"dbInfo":{"id":"8","lifeTime":"OFFLINE","version":"52"}}
答案 0 :(得分:0)
您可以使用:
WHERE raw_data -> 'dbInfo' ->> 'id' = "8" AND raw_data -> 'dbInfo' ->> 'lifeTime' = "DELETED";
,并将使用dbInfo.id = 8和dbinfo.lifeTime = DELETED更新所有元组(行)
全部说明:
UPDATE WORKER_DATA
SET raw_data = '{"dbInfo":{"id":"8","lifeTime":"OFFLINE","version":"52"}}'
WHERE
raw_data -> 'dbInfo' ->> 'id' = "8"
AND raw_data -> 'dbInfo' ->> 'lifeTime' = "DELETED";
在这个小提琴中,您可以看到示例: