collect_set for Google bigquery

Viewed 3819

Hi I was not able to find this anywhere.

How do I do a collect_set in Google BigQuery?

I have a query already written in Big query

select user_id, steps, from table

I need to put all of the steps for each user_id into an array like collect_set would.

3 Answers

You may get the result you want with ARRAY_AGG(DISTINCT ), for instance

SELECT 
    ARRAY_AGG(DISTINCT value)
FROM 
    UNNEST([1, 1, 2, 3, 3, 3, 5]) AS value

gives you an array with [1, 2, 3, 5]

Related