I have a table that is partitioned by date so something like ‘tablename_20191205’. Is there a way for me to run the query everyday without having to modify the date? Also how would I do this if I am using two tables.
So instead of typing,
Select * From 'tablename_20191205'
as table1 and 'tablename2_20191205'
as table2 and modifying the date everyday.
Can I do the following?
Select * From 'tablename_CurrentDate()'
and 'tablename2_CurrentDate()'
I am not quire familiar with how to query date partitioned tabled. Any help is appreciated. Thank you!
Advertisement
Answer
Below is for BigQuery Standard SQL
SELECT * FROM `project.dataset.tablename*` WHERE _TABLE_SUFFIX = CONCAT('_' , FORMAT_DATE('%Y%m%d', CURRENT_DATE()) OR _TABLE_SUFFIX = CONCAT('2_', FORMAT_DATE('%Y%m%d', CURRENT_DATE())