I am trying to select data from the latest partition in a date-partitioned BigQuery table, but the query still reads data from the whole table.
I\'ve tried (as far a
I found the workaround to this issue. You can use with statement, select last few partitions and filter out the result. This is I think better approach because:
Example with last 3 partitions scan:
WITH last_three_partitions as (select *, _PARTITIONTIME as PARTITIONTIME
FROM dataset.partitioned_table
WHERE _PARTITIONTIME > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 3 DAY))
SELECT col1, PARTITIONTIME from last_three_partitions
WHERE PARTITIONTIME = (SELECT max(PARTITIONTIME) from last_three_partitions)