Question:Is it possible to do something like the following in BigQuery?
Or perhaps there’s a better way to do it? Currently the way I’m doing it is the following, but I want to see if I can inline it into the
SELECT country, id FROM -- possible to in-line this, with an array or struct even? [['us', 1], ['ca',2]] AS country (country, id)
WITH country AS ( SELECT 'us' AS country, 1 as id UNION ALL SELECT 'ca', 2 )
Answer:Another possible option would be to make it ARRAY<STRUCT<>> type. Consider below:
SELECT * FROM UNNEST([ STRUCT('us' AS country, 1 AS id), STRUCT('ca',2) ]);
If you have better answer, please add a comment about this, thank you!