Reputation: 563
I have two queries which work correct separately but together there is an error:
WITH minimum_time AS
(
SELECT DATE (min(_PARTITIONTIME)) AS minimums
FROM `Day`
WHERE DATE (_PARTITIONTIME) = "2020-11-20"
)
SELECT *
FROM `Day`
WHERE DATE (_PARTITIONTIME) > (SELECT minimums
FROM minimum_time)
and I get this error:
Cannot query over table 'Day' without a filter over column(s) '_PARTITION_LOAD_TIME', '_PARTITIONDATE', '_PARTITIONTIME' that can be used for partition elimination
I do not quite understand why this is happening, first query returns a date.
Upvotes: 1
Views: 982
Reputation: 5518
You were getting the error because:
In general, partition pruning will reduce query cost when the filters can be evaluated at the outset of the query without requiring any subquery evaluations or data scans.
The workaround is using BigQuery Scripting to pre-determine the partition filter, like:
DECLARE minimums DATE DEFAULT ((SELECT minimums FROM `Day` WHERE ...));
SELECT *
FROM `Day`
WHERE DATE (_PARTITIONTIME) > minimums; -- minimums is a constant to the second query
Upvotes: 1