How to Schedule Queries in Snowflake

Galaxy Glossary

How do I schedule recurring SQL queries in Snowflake?

Use Snowflake TASK objects to run SQL statements automatically on a defined cron schedule or after another task completes.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Table of Contents

How to schedule queries in Snowflake

Snowflake TASK objects let you automate recurring SQL so reports, ETL steps, and data quality checks run without manual effort.

What is a Snowflake TASK?

A TASK is a first-class object that stores a SQL statement and a schedule. Snowflake’s engine wakes the task at the requested interval, spins up the assigned warehouse, executes the SQL, and shuts the warehouse down when idle.

When should I schedule queries?

Schedule queries when you need repeatable data loads, nightly aggregations, hourly data quality alerts, or event-driven chains that follow each other in order. Automation removes the risk of missed runs and keeps dashboards fresh.

How do I create a cron-based TASK?

Use CREATE TASK with the SCHEDULE option. Provide CRON expression, time zone, warehouse, and the SQL to run. Snowflake validates the cron string before saving.

Example: daily revenue snapshot

The example below takes yesterday’s orders, sums revenue, and inserts into a reporting table. It runs at 01:00 UTC every day.

CREATE OR REPLACE TASK daily_revenue_snapshot
WAREHOUSE = reporting_wh
SCHEDULE = 'USING CRON 0 1 * * * UTC'
AS
INSERT INTO daily_order_revenue (snapshot_date, total_amount)
SELECT CURRENT_DATE - 1,
SUM(total_amount)
FROM Orders
WHERE order_date = CURRENT_DATE - 1;

How do I start, stop, or modify a TASK?

New tasks are created in the SUSPENDED state. Use ALTER TASK … RESUME to activate, SUSPEND to pause, and SET to change the warehouse or schedule without recreation.

Can I chain tasks?

Yes. Replace SCHEDULE with AFTER <preceding_task>. The child task fires only after the parent finishes successfully. Build multi-step pipelines without external orchestration.

Best practices for scheduled queries

Use a size-appropriate warehouse and AUTO_SUSPEND ≤60 seconds to control cost. Add COMMENT for easy discovery. Keep SQL idempotent so reruns don’t duplicate data. Monitor task history via SNOWFLAKE.ACCOUNT_USAGE.TASK_HISTORY.

Why How to Schedule Queries in Snowflake is important

How to Schedule Queries in Snowflake Example Usage


/* Hourly inventory alert when stock < 10 */
CREATE OR REPLACE TASK low_stock_alert
  WAREHOUSE = ops_wh
  SCHEDULE = 'USING CRON 0 * * * * America/Los_Angeles'
AS
INSERT INTO alerts (alert_time, product_id, current_stock)
SELECT CURRENT_TIMESTAMP, id, stock
FROM   Products
WHERE  stock < 10;

How to Schedule Queries in Snowflake Syntax


CREATE [ OR REPLACE ] TASK [ IF NOT EXISTS ] task_name
  WAREHOUSE = warehouse_name
  [ SCHEDULE = 'USING CRON cron_expression timezone' | AFTER preceding_task ]
  [ COMMENT = 'description' ]
AS
-- single SQL statement to execute;

-- Helper commands
ALTER TASK task_name { RESUME | SUSPEND | SET &lt;parameter&gt; = &lt;value&gt; };
DROP TASK IF EXISTS task_name;

Common Mistakes

Frequently Asked Questions (FAQs)

Does a TASK support multi-statement scripts?

No. A TASK accepts exactly one SQL statement. Wrap multiple steps in a stored procedure and call the procedure from the task.

How do I debug a failed TASK?

Query ACCOUNT_USAGE.TASK_HISTORY or INFORMATION_SCHEMA.TASK_HISTORY to see error messages, SQL text, and execution times. Fix the SQL, then manually EXECUTE TASK to retest.

Can I run a task on demand?

Yes. Use EXECUTE TASK task_name to trigger it immediately, regardless of the defined schedule.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.