将JSON字符串转换为JSONB [英] Convert JSON string to JSONB

查看:138
本文介绍了将JSON字符串转换为JSONB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有jsonb字段的表.其中一些行是对象数组,而其他一些则是字符串.

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.

我的表结构:

我如何在PostgreSQL中做到这一点?

How I can do this in PostgreSQL?

推荐答案

以下SQL应该可以解决问题:

Following SQL should do the trick:

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

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

这篇关于将JSON字符串转换为JSONB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆