Each user's set of products

Each user's set of products

From the events table (columns user_id, product_id, event_type, ts) build, for each user_id, a sorted array of the distinct product_id values they interacted with. Return columns user_id and products (array sorted ascending). Order the result by user_id.

Expected output sample

user_idproducts
10[1]
11[1]
12[2]
PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid