[英]Postgres query to convert stringifyed json object to jsonb object
通过执行一些正则表达式替换,我能够解决同一问题。 您可能不需要where子句,但就我而言,我有一个错误开始对JSONB列进行字符串化,因此仅部分数据需要应用此更改。
update your_table
set text =
jsonb(regexp_replace(regexp_replace(regexp_replace(text::text, '"$', ''), '^"+', ''), '\\"', '"', 'g'))
where text->>'foo' is null;
你可以做to_json('{ \\"foo\\": \\"bar\\" }'::text)
所以就像
update yourtable set yourjsoncolumn = to_json(yourjsoncolum::text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.