PostgreSQLAggregate FunctionsJSON_AGG
ARRAY_AGG

JSON_AGGAggregate Functions

JSONB_AGG

Aggregates values into a JSON array.

Syntax

JSON_AGG(expr)

Example

Enter values below to update the example in real time.

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;