我有一个数据库,其中有table
。我的表id
中有两列,现在我要获取表中的所有jsonb
。对类型name
的描述。要怎么做
我尝试过这种方法,但是没有用
SELECT description::jsonb->name FROM Category
预期输出
["hello","test","world"]
您可以使用聚合:json[b]_agg()
可用于生成由原始对象的所有'name'
属性组成的json数组,按id
排序。
select jsonb_agg(description ->> 'name' order by id) res from category
注意,由于description
的数据类型为jsonb
,因此不需要额外的转换。