Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bigquery- Declaring an array from list of Integers

I am trying to declare a list of integers as a variable named list_of_ints. My code works, but it seems to be a bit of a workaround:

DECLARE list_of_ints ARRAY <INT64>;
set list_of_ints = (
  SELECT ARRAY_AGG( DISTINCT some_ints)
  FROM (SELECT * FROM UNNEST ([11,22,33]) as some_ints) 
);

I was hoping for something along the lines of

DECLARE list_of_ints ARRAY <INT64>;
set list_of_ints = ARRAY([11,22,33]);

but it seems that this is improper syntax. Is there a way akin to the above attempt to declare an array as a variable in bigquery?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

use below

DECLARE list_of_ints ARRAY <INT64>;
SET list_of_ints = [11,22,33];    

OR

DECLARE list_of_ints ARRAY <INT64> DEFAULT [11,22,33]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading