'Unable to get the square brackets for the single individual records while using the json_agg inside the json_compose in Teradata-sql-assistance
According to the documentation, if we have the following data in a table named emp_table
empID company empName empAge
1, 'Teradata', 'Cameron', 24
2, 'Teradata', 'Justin', 34
3, 'Apple', 'Someone', 34
and if we use the following query :
SELECT JSON_Compose(T.company, T.employees) FROM ( SELECT company, JSON_agg(empID AS id, empName AS name, empAge AS age) AS employees FROM emp_table GROUP BY company ) AS T;
we are supposed to get :
JSON_Compose
------------
{
"company" : "Teradata",
"employees" : [
{ "id" : 1, "name" : "Cameron", "age" : 24 },
{ "id" : 2, "name" : "Justin", "age" : 34 }
]
}
{
"company" : "Apple",
"employees" : [
{ "id" : 3, "name" : "Someone", "age" : 24 }
]
}
But when I try to follow the same steps, I'm not able to get the square bracket for the individual records. The result I'm getting is :
JSON_Compose
------------
{
"company" : "Teradata",
"employees" : [
{ "id" : 1, "name" : "Cameron", "age" : 24 },
{ "id" : 2, "name" : "Justin", "age" : 34 }
]
}
{
"company" : "Apple",
"employees" :
{ "id" : 3, "name" : "Someone", "age" : 24 }
}
Is there any way to get square bracket for individual records as well ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
