[英]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.