数据仓库服务 GAUSSDB(DWS)-JSON/JSONB函数:jsonb_agg

时间:2024-12-06 15:12:47

jsonb_agg

描述:将jsonb对象聚合成jsonb数组。

返回类型:jsonb

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
SELECT * FROM json_tbl_2;
 a |  b
---+-----
 1 | aaa
 1 | bbb
 2 | ccc
 2 | ddd
(4 rows)

SELECT a, jsonb_agg(b) FROM json_tbl_2 GROUP BY a ORDER BY a;
 a |   jsonb_agg
---+----------------
 1 | ["aaa", "bbb"]
 2 | ["ccc", "ddd"]
(2 rows)
support.huaweicloud.com/sqlreference-910-dws/dws_06_0356.html