How to create temporary table in Google BigQuery

Vasundhara picture Vasundhara · Dec 19, 2013 · Viewed 42.8k times · Source

Is there any way to create a temporary table in Google BigQuery through:

SELECT * INTO <temp table> 
FROM <table name> 

same as we can create in SQL?

For complex queries, I need to create temporary tables to store my data.

Answer

Felipe Hoffa picture Felipe Hoffa · May 8, 2018

2018 update - definitive answer with DDL

With BigQuery's DDL support you can create a table from the results a query - and specify its expiration at creation time. For example, for 3 days:

#standardSQL
CREATE TABLE `fh-bigquery.public_dump.vtemp`
OPTIONS(
  expiration_timestamp=TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 3 DAY)
) AS
SELECT corpus, COUNT(*) c
FROM `bigquery-public-data.samples.shakespeare`
GROUP BY corpus