【发布时间】:2018-05-23 01:52:00
【问题描述】:
我需要全局替换出现在嵌套 JSON 结构中多个位置的特定字符串,该字符串以 jsonb 形式存储在 postgres 表中。例如:
{
"location": "tmp/config",
"alternate_location": {
"name": "config",
"location": "tmp/config"
}
}
...应该变成:
{
"location": "tmp/new_config",
"alternate_location": {
"name": "config",
"location": "tmp/new_config"
}
}
我试过了:
UPDATE files SET meta_data = to_json(replace(data::TEXT, 'tmp/config', 'tmp/new_config'));
不幸的是,这会导致 JSON 格式错误,带有三重转义引号。
任何想法如何做到这一点?
【问题讨论】:
-
这不是一个有效的 JSON。
-
@klin,哎呀,我让示例 json 有效。
标签: json postgresql jsonb postgresql-9.6