We have a BigQuery query that joins two tables, one of those tables is partitioned on DATE. As a first step i added a date literal into the query, which works perfect.
SELECT a.hello,b.ciao FROM table a INNER JOIN table b ON a.time = b.time AND b.date = '2021-10-03'
Now it is time to add multiple days this to prune only the partitions that are relevant.
Attempt one: using a subquery, this does not work, subquery not allowed
SELECT a.hello,b.ciao FROM table a INNER JOIN table b ON a.time = b.time AND b.date IN (SELECT mytimes FROM table)
Attempt two: use ARRAY and UNNEST, does not work (i receive the same error when you do not have a filter at all: error: cannot query over table without a filter)
Querying a Partitioned table in BigQuery using a reference from a joined table
DECLARE date_filter ARRAY DEFAULT (SELECT ARRAY_AGG(day) FROM table);
SELECT a.hello,b.ciao FROM table a INNER JOIN table b ON a.time = b.time AND b.date IN UNNEST(data_filter)
Something I thought was going to be easy seems not so easy after all, can someone guide me to a solution? Many thx.