Study FAQ
How do I schedule or trigger a Snowflake task and choose its compute?
Also asked as 2
- What makes a Snowflake task start, and what permissions does its compute model require?
- How do I run Snowflake SQL on a clock or stream trigger with warehouse or serverless compute?
Answer
Use SCHEDULE for time-based work and a stream condition in WHEN for event-driven work. Assign a warehouse for user-managed compute or omit WAREHOUSE for serverless compute. Newly created tasks are suspended, so resume the task to enable routine scheduled or triggered runs.
A scheduled task can also check a WHEN condition at each scheduled run. A dedicated triggered task uses WHEN SYSTEM$STREAM_HAS_DATA('db.schema.stream_name') without SCHEDULE. For a serverless triggered task, specify TARGET_COMPLETION_INTERVAL. A user-managed triggered task instead names its warehouse. Write the transformation so an empty change set is harmless because SYSTEM$STREAM_HAS_DATA can return a false positive.
The creating role needs the required container and CREATE TASK privileges. By default, execution uses the task owner's privileges. The owner needs global EXECUTE TASK, the privileges the SQL itself requires, and either USAGE on the user-managed warehouse or global EXECUTE MANAGED TASK for serverless execution. Use EXECUTE TASK for a controlled manual test and verify task history and target results. Then use ALTER TASK ... RESUME to enable normal operation and check that the expected trigger or schedule is recorded.
Introduction to tasks · CREATE TASK · Triggered tasks · SYSTEM$STREAM_HAS_DATA
Full explanation
Snowflake SQL Transformation, Streams, Tasks, and Pipeline Patterns
Study guide · COF-C03
Read the full explanation