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

时间:2024-11-05 19:19:06

jsonb_object_agg

描述:将键/值对聚集成一个JSON对象。

返回类型:jsonb

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
SELECT * FROM json_tbl_3;
 a |  b  | c
---+-----+----
 1 | aaa | 10
 1 | bbb | 20
 2 | ccc | 30
 2 | ddd | 40
(4 rows)
SELECT a, jsonb_object_agg(b, c) FROM json_tbl_3 GROUP BY a ORDER BY a;
 a |    jsonb_object_agg
---+------------------------
 1 | {"aaa": 10, "bbb": 20}
 2 | {"ccc": 30, "ddd": 40}
(2 rows)
support.huaweicloud.com/sqlreference-dws/dws_06_0356.html