PostgreSQL集計関数JSON_AGG
ARRAY_AGG

JSON_AGG集計関数

JSONB_AGG

値をJSON配列に集計します。

構文

JSON_AGG(expr)

使用例

下記の値を入力するとサンプルに即時反映されます。

order_id
product_name
products
order_items
USING
product_id
-- 주문별 상품 목록 JSON
SELECT order_id, JSON_AGG(product_name) AS products
FROM order_items
JOIN products USING (product_id)
GROUP BY order_id;