您好,我正在尝试在我的 json 列中添加/更新数据 - 其中的值为 NULL 运气不好 - 这是我的错误查询
update departments
set (data->>'formal_name') = departments.name
where (data->>'formal_name') is null
谢谢你的建议
最佳答案
除非您使用的是 PostgreSQL 9.5 的某些 Alpha 版本,否则您无法更新 JSON 列中的数据:
此外,请考虑此答案中给出的建议:
How to perform update operations on columns of type JSONB in Postgres 9.4
如果您确实需要修改 JSON 字段中的数据,您可能必须使用 json_array_elements() 分解 JSON,然后作为一个整体重新构建它,如下所述:
https://dba.stackexchange.com/questions/54283/how-to-turn-json-array-into-postgres-array
关于sql - 如何使用 NULL 值更新 JSON 列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32763172/