次の例では、パラメータ名を割り当てる方法、およびGROUP BY句を使用する方法を示します。
SELECT JSON_agg(empID AS id, empName AS name) FROM emp_table GROUP BY company, empAge;
結果:
JSON_AGG(empID AS id,empName AS name) -------------------------------------------------------------------------- {"id":2,"name":"Justin"} [{"id":3,"name":"Someone"},{"id":1,"name":"Cameron"}]