What is a Snowflake Task?
A Snowflake Task is a feature that allows users to schedule and automate SQL statements or procedural logic within Snowflake. Tasks are primarily used to orchestrate workflows, such as data transformations, periodic reports, and pipeline execution, without requiring external scheduling tools.
Key Features of Snowflake Tasks:
- Automated Execution – Tasks can be scheduled at specific intervals or triggered by other tasks.
- Dependency Management – Tasks can form task trees, where one task triggers another.
- Support for SQL & Procedural Logic – Execute SQL statements, stored procedures, or JavaScript-based procedural code.
- Flexible Scheduling – Tasks can run at fixed intervals (e.g., every 5 minutes) or based on event-driven dependencies.
How to Create and Use Snowflake Tasks
1. Creating a Basic Task
A simple task that runs a SQL statement at a scheduled interval:
CREATE TASK my_task
WAREHOUSE = my_warehouse
SCHEDULE = '5 MINUTE'
AS
INSERT INTO report_table
SELECT * FROM source_table;
2. Creating a Task with Dependencies
Tasks can be linked in a sequence to form a task tree:
CREATE TASK task_1
WAREHOUSE = my_warehouse
SCHEDULE = '10 MINUTE'
AS
UPDATE my_table SET processed = TRUE;
CREATE TASK task_2
AFTER task_1
WAREHOUSE = my_warehouse
AS
INSERT INTO audit_log SELECT CURRENT_TIMESTAMP, 'task_1 completed';
3. Checking the Status of a Task
To view details of a task:
SHOW TASKS;
Or for a specific task:
SELECT * FROM INFORMATION_SCHEMA.TASK_HISTORY WHERE NAME = 'my_task';
4. Enabling and Running a Task
Tasks are created in a suspended state by default. Enable and manually execute a task with:
ALTER TASK my_task RESUME;
EXECUTE TASK my_task;
Best Practices for Snowflake Tasks
- Use Resource Monitors – Monitor resource consumption and prevent runaway tasks from consuming excessive credits.
- Set Appropriate Scheduling Intervals – Avoid setting overly frequent schedules that could overwhelm your system.
- Use Task Trees for Complex Workflows – Structure dependencies efficiently using
AFTER
to create a logical execution order. - Monitor Task Failures – Regularly check
TASK_HISTORY
and set up alerting for failures to ensure tasks run as expected. - Optimize Warehouse Usage – Assign tasks to appropriately sized virtual warehouses to balance cost and performance.
- Leverage Cloning for Testing – Before modifying a production task, test it using cloned tables to avoid unintended data modifications.
- Minimize Long-Running Tasks – Break large processing tasks into smaller, incremental steps to improve maintainability and performance.
Use Cases for Snowflake Tasks
- Data Pipeline Automation – Transform and load data at regular intervals.
- ETL & ELT Workflows – Automate extract, transform, and load operations within Snowflake.
- Incremental Data Processing – Process only new or changed data efficiently.
- Scheduling Reports – Generate and refresh reports periodically.
- Orchestration of Complex Workflows – Chain multiple tasks for end-to-end data operations.
Using Snowflake with Evidence
For teams looking to streamline reporting and analytics using Snowflake, Evidence provides seamless integration. With Evidence, you can:
- Automate reporting workflows using Snowflake Tasks.
- Query and visualize data processed by Snowflake Tasks.
- Track scheduled data updates and build real-time dashboards.
Learn more about integrating Snowflake and Evidence by visiting the Evidence documentation.