Convert JSON string to JSONB

守給你的承諾、 提交于 2021-02-11 16:41:49

问题


I have a table with jsonb field. Some of the rows are an array of objects, but some of the others are string.

I want to convert red rows to array of objects.

My table structure:

How I can do this in PostgreSQL?


回答1:


Following SQL should do the trick:

update your_table_name 
set content =  (content#>>'{}')::jsonb 
where jsonb_typeof(content)='string';

Reference: https://www.postgresql.org/docs/10/functions-json.html



来源:https://stackoverflow.com/questions/60824247/convert-json-string-to-jsonb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!