简体   繁体   中英

How to fetch data for a specific time period in BigQuery

Please, I created my table using hour time partition. Please, I would like would like to fetch data that was stored in my table in the last X minutes, eg last 5 minutes.

I tried using this command SELECT * FROM mydataset.mytable FOR SYSTEM_TIME AS OF TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 5 MINUTE);

But, it returns a lot more rows than what is expected. I typically store 500 rows every 2 minutes, but this query is returning more than 30000 rows

As @Samuel mentioned in the comment, below example query can be considered to fetch data for a specific time period in BigQuery.

Select * from `dataset.table` 
WHERE col_timestamp < TIMESTAMP_SUB(CURRENT_TIMESTAMP(), 
INTERVAL 5 MINUTE)

Posting the answer as community wiki for the benefit of the community that might encounter this use case in the future.

Feel free to edit this answer for additional information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM