0
votes

I'm having a problem trying to query for 15 months worth of data. I know about bigquery's wildcard functions, but I can't seem to get them to work with my tables.

For example, if my tables are called:

xxxx_201501,
xxxx_201502,
xxxx_201503,
...
xxxx_201606

How can I select everything from 201501 until today (current_timestamp)?

It seems that it's necessary to have the tables per day, am I wrong?

I've also read that you can use regex but can't find the way.

2

2 Answers

2
votes

With Standard SQL, you can use a WHERE clause on a _TABLE_SUFFIX pseudo column as described here:

Is there an equivalent of table wildcard functions in BigQuery with standard SQL?

In this particular case, it would be:

SELECT ... from `mydataset.xxx_*` WHERE _TABLE_SUFFIX >= '201501';
1
votes

This is a bit long for a comment.

If you are using the standard SQL dialect, then I don't think the functionality is yet implemented.

If you are using the legacy SQL dialect, then you can use a function such as TABLE_DATE_RANGE(). This and other table wildcard functions are well documented.

EDIT:

Oh, I see. The simplest way would be to store the tables as YYYYMM01 so you can use the range query.

But, you can also use table_query():

from table_query(t, 'right(table_id, 6) >= ''201501'' ')