BigQuery: dynamically select table by the current date in Standard SQL?

折月煮酒 提交于 2019-12-30 07:48:31

问题


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())


来源:https://stackoverflow.com/questions/57817881/bigquery-dynamically-select-table-by-the-current-date-in-standard-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!