如何从Postgres中的jsonb列获取数据?

问题描述 投票:0回答:1

我有一个数据库,其中有table。我的表id中有两列,现在我要获取表中的所有jsonb。对类型name的描述。要怎么做

我尝试过这种方法,但是没有用

SELECT description::jsonb->name FROM Category 

enter image description here

预期输出

["hello","test","world"]
postgresql postgis postgresql-9.1 postgresql-9.4
1个回答
0
投票

您可以使用聚合:json[b]_agg()可用于生成由原始对象的所有'name'属性组成的json数组,按id排序。

select jsonb_agg(description ->> 'name' order by id) res from category

注意,由于description的数据类型为jsonb,因此不需要额外的转换。

© www.soinside.com 2019 - 2024. All rights reserved.