-->

BigQuery: dynamically select table by the current

2020-04-01 03:05发布

问题:

I am trying to find the table of the current date of

SELECT * 
FROM `da`.`m`.`ga_realtime_20190306`

but not working

SELECT * 
FROM `da`.`m`.`CONCAT('ga_realtime_', FORMAT_DATE('%Y%m%d', CURRENT_DATE())`

How can I dynamically select a table with CURRENT_DATE and the BigQuery Standard query?

回答1:

Use wildcard and _TABLE_SUFFIX

SELECT
  field1,
  field2,
  field3
FROM
  `my_dataset.ga_realtime_*`
WHERE
  _TABLE_SUFFIX = FORMAT_DATE('%Y%m%d', CURRENT_DATE())