Summarised Question:
How can I query a view that is based off a wildcard table using _TABLE_SUFFIX
as a filter, rather than a column (which would query all the tables)?
e.g.
SELECT Name, date, weight
FROM `my_view`
WHERE _TABLE_SUFFIX >= '2020-01-01'
rather than
SELECT Name, date, weight
FROM `my_view`
WHERE date >= '2020-01-01'
Detailed Question:
Say I have a table bq.school.weights_20191231
with the following format
| Name | Date | Weight |
|-------|------------|--------|
| Bob | 2019-12-31 | 55kg |
| Alex | 2019-12-31 | 95kg |
| ... | ... | .. |
| Sandy | 2019-12-31 | 43kg |
and a table bq.school.weights_20200101
| Name | Date | Weight |
|-------|------------|--------|
| Bob | 2020-01-01 | 60kg |
| Alex | 2020-01-01 | 100kg |
| ... | ... | .. |
| Sandy | 2020-01-01 | 40kg |
And I create a view based off the base table bq.school.weights_*
called weights_view
, e.g.
SELECT Name, Date, Weight
FROM `bq.school.weights_*`
How can I query weights_view
using _TABLE_SUFFIX
to filter the date, rather than using WHERE DATE = "2020-01-01"
(which would query all the tables)?