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

时间:2024-01-26 16:15:25

json_object_agg(any, any)

描述:将值聚集为json对象。

返回类型: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 json_object_agg(name, score) FROM classes group by name order by name;
     json_object_agg
-------------------------
 { "A" : 2, "A" : 3 }
 { "D" : 5, "D" : null }
(2 rows)
support.huaweicloud.com/sqlreference-820-dws/dws_06_0356.html