Effective query in BigQuery Query

I am trying to efficiently query from the last table in a dataset that consists of form tables project_id:dataset:dataset_20160101, project_id:dataset:dataset_20160102etc.

This query seems to be the recommended solution:

SELECT * 
FROM `project_id.dataset.*`
WHERE _TABLE_SUFFIX=(SELECT MAX(table_id) FROM `project_id.dataset.__TABLES_SUMMARY__`)

However, this query forces me to access all the tables in the data set, not just the last one. Why is this?

+4
source share
2 answers

, , WHERE , , _TABLE_SUFFIX = 'dataset_20160102'. , WHERE -Uery, , . , . - .

. , , . ETA.

0

, , , (1) MAX (table_id) (2) :

SELECT
        *,
        DATE max_table_id AS _LATEST_DATE,
        PARSE_DATE('%E4Y%m%d', _TABLE_SUFFIX) AS _DATA_DATE
FROM `project_id.dataset.*`

, , _DATA_DATE = _LATEST_DATE. _LATEST_DATE , . , .

0

Source: https://habr.com/ru/post/1679661/


All Articles