To schedule queries in BigQuery, you use Scheduled Queries in the BigQuery UI, the bq command-line tool, or Terraform/API. Here’s how to do it via the UI (most common approach):
Step-by-Step: Schedule a Query in BigQuery UI
- Open BigQuery Console
- Go to: https://console.cloud.google.com/bigquery
- Write Your Query
- Open the SQL editor and write your query (e.g., a snapshot insert query).
- Click on “Schedule”
- You’ll see a “Schedule” button just above the query editor.
- Click it and then select “Create new scheduled query”.
- Set Job Details
- Name your job.
- Choose Project and Location (typically US or EU).
- Set Frequency
- Choose from predefined intervals: Hourly, Daily, Weekly, Monthly, or Custom using cron expressions.
- Example (daily at midnight): 0 0 * * *
- Set Start Time
- Define when the schedule should start.
- Destination (optional)
- If your query writes results to a table, you can configure the destination table and write behavior (e.g., append or overwrite).
- Notification Settings (optional)
- Set up email notifications or connect to Cloud Logging.
- Save
- Click Save to create the scheduled query.
Optional Tips
- Permissions Needed:
- You need bigquery.jobs.create permission (usually included in roles like BigQuery Admin or Editor).
- Monitor Jobs:
- Navigate to BigQuery > Scheduled Queries to view or manage existing schedules.
Would you like a CLI version (bq command) or cron-style examples?