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

时间:2024-10-25 17:35:14

json_agg(any)

描述:将值聚集为json数组。

返回类型:array-json

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
SELECT * FROM classes;
 name | score
 -----+-------
 A    |     2
 A    |     3
 D    |     5
 D    | 
(4 rows)    
SELECT name, json_agg(score) score FROM classes group by name order by name;
 name |      score
 -----+-----------------
 A    | [2, 3]
 D    | [5, null]
      | [null] 
(3 rows)
support.huaweicloud.com/sqlreference-dws/dws_06_0356.html