To schedule a query, first open the tab containing the query you'd like to schedule. If the query hasn't been written yet, open a new tab and write out the SQL.
Then, click on the scheduler icon that appears to the right of your query tabs (show below).
Before scheduling your query, you'll need to set up the scheduler.
Your query scheduler settings (screenshot at the end) contain four main sections:
Give your scheduled query a recognizable name. This will help you identify the query if you have multiple scheduled queries.
By default, the name you've given the query tab will be used.
Determine how often you'd like the query to execute.
Select one of the preset options in the dropdown, or customize your interval.
This is just like setting up a destination table for a regular query.
Give the table a recognizable name, and decide whether you'd like the results to append to or overwrite the table's previous results.
Decide whether you'd like to receive alerts when the query executes successfully, fails, or both.
You can save tons of time by setting up a series of DML statements to execute in a sequence — and how to schedule these in a single scheduler. It might look a little bit like this:
CREATE TABLE IF NOT EXISTS `myproject.mydataset.mytable` (the_time TIMESTAMP,customer_name STRING,item_name STRING,item_id NUMERIC NOT NULL,price NUMERIC);INSERT INTO `myproject.mydataset.mytable` (the_time, customer_name, item_name, item_id, price)VALUES ('2019-08-01 12:41:11', 'John Smith' 'MacBook Pro', '1245124', 2000);SELECT * FROM `myproject.mydataset.mytable`;
superQuery detects from the syntax whether to execute these queries in parallel, or in a sequence.
To do so, write out your queries as you would in a Query Tab, separated by a semicolon. Then create your scheduled query as normal, except do not include a destination table when configuring the settings.
There are a couple unique characteristics about superQuery's scheduler. Notably, you can:
Schedule queries that Create, Update, and Delete other tables.
Set Job priority to Batch mode to help in cases when the scheduled query is triggered during high load times (when using Slots). BigQuery's engine will allocate resources at the best time.
Select the billing project the query will be executed on while defining another project inside your SQL.