Tech Blog

Coding, Technology

Temporary Tables in BigQuery

By Jigna Chandarana2 min read
← Back to blog

Data is extracted from the BigQuery with the help of some SQL queries and provides the result in some temporary table. BigQuery temporary table can cache the query results, name them randomly and stored in a special database. Temporary table is stored in BigQuery for 24 hours and we can also retain/query that table and after 24 hours it gets deleted automatically.

Let’s query one table and go to the Job Information tab.

Over here you can see Job Id, table location, Destination table and many other things. Now click on Temporary Table and you will get a tab like this.

Table ID is the table name of a temporary table. Now run the same query again and go to the Job Information tab.

You’ll see Duration: 0.0 Seconds and Bytes processed: 0 Bytes. And click on Temporary Table.

Over here you can see after running the query for the first time and second time, same temporary table is there. So, If you are running the same query within 24 hours, BigQuery is smart enough to recognize that and you’ll get the same temporary table and charged only once!

In some of the cases we require to query temporary tables without using subquery, or we need temporary tables in some jobs. In this scenario we can use temporary Table ID.

public static void UseTemporaryTable (string Query,BigQueryClient client)
{
     BigQueryResults result = client.ExecuteQuery(query, null);

     string query2= "select * from " + result.TableReference.DatasetId + "." + result.TableReference.TableId;

	BigQueryResults result2 = client.ExecuteQuery(query2, null);
}

public static JobState exportToGCS(BigQueryResults result, BigQueryClient client, string fileName)
        {
            BigQueryJob job = client.CreateExtractJob(result.TableReference, fileName);
            Console.WriteLine("CreateExtractJob ran");
            job = job.PollUntilCompleted().ThrowOnAnyError();
            JobState jobState = job.State;
            return jobState;
        }

One thing to note is, we cannot share temporary tables and BigQuery does not charge us to store temporary tables. And temporary tables is only accessible in the session that was created in.

Keep reading

You may be interested in

Browse all articles →
How Angular is Different from AngularJS
September 27, 20227 min read

How Angular is Different from AngularJS

What is Angular? Angular is a popular open-source Typescript framework and free to use. Considered to be a JavaScript-based framework,TypeScript.is its primary programming language. TypeScript is Developed by Microsoft and its superset of JavaScript, which simply means that TypeScript has all the capabilities that JS has and more additional features. Angular is majorly used for […]

By Sachin DevadigaRead More →
Angular constructor vs ngOnInit
September 15, 20223 min read

Angular constructor vs ngOnInit

Overview: If you are new to angular or have been working with it for a while, you will have questions like: Is it necessary to inject dependencies in the constructor and bind data? When should we use ngOnInit ? What is the difference between constructor and OnInit?. So, in this blog we will answer all […]

By Priyanka SRead More →
Angular – Difference between ng-container and ng-template
July 13, 20222 min read

Angular – Difference between ng-container and ng-template

Overview: ng-container and ng-template, both are angular elements which will work like containers with HTML elements, but with different purpose/use cases. Lets see what is the use of ng-container and ng-template below: ng-container: In some cases when you do not want to add an extra HTML element to the DOM , for example like div […]

By Priyanka SRead More →