A task in Snowflake is a database object that lets you run SQL statements (often INSERT
, COPY INTO
, or CALL
to a stored procedure) on a schedule or based on dependencies.
- Trigger:
- Time-based — uses CRON expressions or simple intervals using
SCHEDULE
syntax (e.g., every 5 minutes). - Dependency-based — runs only after another task completes using
AFTER
syntax, which generate a task graph
- Time-based — uses CRON expressions or simple intervals using
- Common uses:
- Periodic
COPY INTO
from a stage to a table. - Data transformations in ELT pipelines.
- Chaining tasks for multi-step workflows.
- Periodic
Task creation workflow overview¶
- Create a task administrator role that can run the commands in the following steps.
- Define a new task using CREATE TASK.
- Manually test tasks using EXECUTE TASK.
- Allow the task to run continuously using ALTER TASK … RESUME.
- Monitor task costs
- Refine the task as needed using ALTER TASK. Ref: https://docs.snowflake.com/en/user-guide/tasks-intro
Compared with Snowflake - Dynamic table
Feature / Aspect | Dynamic Table | Dependency-based Task |
---|---|---|
Primary purpose | Keep a table automatically updated from a query | Run SQL or stored procedures in a defined sequence |
Trigger | Target lag interval (Snowflake manages refresh) | Explicit AFTER dependency or schedule |
Execution control | Snowflake decides when to refresh to meet target lag | Full control over exact run order and timing |
Workflow complexity | Single-step, SQL-only transformation | Multi-step workflows with branching and procedural logic |
Use with external systems | Not supported | Supported (e.g., send notifications, call APIs) |
Non-SQL operations | Not possible | Possible via stored procedures or external functions |
Latency control | Approximate — Snowflake aims to meet target lag | Exact — runs immediately after dependency finishes |
Maintenance | Minimal — Snowflake handles refresh logic | You manage scheduling, chaining, and enabling tasks |
Best for | Continuous, incremental data sync | ETL/ELT pipelines, staged loads, complex orchestration |