I've got a query where I need to use a list of strings over and over in a query and would like to declare it once, the only thing is I've only got it working as it is in the second example and would like to not have to UNNEST
DECLARE
list X DEFAULT (
8335, 9776, 11496);
SELECT * FROM `dataset.table` WHERE quantity_sold IN list
X as not sure what type it'd have to be
DECLARE
list ARRAY<INT64> DEFAULT [
8335, 9776, 11496];
SELECT * FROM `dataset.table` WHERE quantity_sold IN UNNEST(list)
this is the "trick" I am usually using in such cases
with my_variables as (
select [8335, 9776, 11496] list1, ['a', 'b', 'c'] list2
# note: this is just one row CTE
)
select *
from `dataset.table`, my_valiables
where quantity_sold in unnest(list1)
and something_else in unnest(list1)
and yet_another_one in unnest(list2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.