arraysgoogle-bigquerybigquery-udf

How can one create an array of ones in BigQuery?


Is there a way to create an array of ones (or anything else) of a given length in Google BigQuery? E.g. like [1]*7 in python, producing the list [1,1,1,1,1,1,1].

The GENERATE_ARRAY(start, end, step) function cannot be used for this.

I have data given to me as a frequency table and would like to expand out.


Solution

  • You can consider below

    -- i.e. [1]*7
    SELECT ARRAY(SELECT 1 FROM UNNEST(GENERATE_ARRAY(1, 7))) ones;