Is it possible in BigQuery to select the latest table only without querying all tables?
I query GA4 data in BigQuery. GA4 delivers an events table every day with the appended date in the nomenclature, like thus:
- ‘data.datasetname_05012024’
- ‘data.datasetname_05022024’
- ‘data.datasetname_05032024’
- ‘data.datasetname_05042024’
- ‘data.datasetname_05052024’
- ‘data.datasetname_05062024’
I have WHERE clause to filter to the latest table only:
Select *
from data.datasetname_*
where _TABLE_SUFFIX = (select max(TABLE_SUFFIX) from `data.datasetname*
This query extracts the required data, but it queries all data sets before applying the filter, which increases the cost of running this query.
The query is scheduled to run every day – is it possible in BigQuery to select the latest table only without querying all tables?
Scott is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.