Example: Use ARRAY_AGG as Input to ARRAY_TO_JSON - Advanced SQL Engine - Teradata Database

JSON Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
gzn1554761068186.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1150
lifecycle
previous
Product Category
Teradata Vantage™
Use the aggregated positions and ages from ARRAY_AGG as input to ARRAY_TO_JSON to obtain a JSON object.
The example uses the table(s) created earlier.
SELECT pos, ARRAY_TO_JSON(ARRAY_AGG(age ORDER BY empId, NEW intarr5()))
FROM employeeTable 
GROUP BY pos
ORDER BY pos;
Result:
pos         ARRAY_TO_JSON(ARRAY_AGG(…))
---------------------------------------
engineer    [24,34,25,21]
executive   [50,51,52,52,60]
manager     [40,41,45,48]
salesman    [31,32,33,40]