Reputation: 91
I'm in need of examples of Snowflake event based TASK Scheduling instead of Time Based task scheduling. I could not find those examples in snowflake document.
thanks in advance
Upvotes: 0
Views: 2449
Reputation: 46
The only event source that can trigger a task is the completion of a prior task in a task tree, see using the "AFTER" parameter.
CREATE TASK mytask2
WAREHOUSE = mywh
AFTER mytask1
AS
INSERT INTO mytable2(id,name) SELECT id, name FROM mytable1;
Also, if the event would be an insert or a change to a record in a table, you can create a stream on the table and use the WHEN clause to keep the scheduled task from running until the stream has data.
create stream mystream on table mytable
APPEND_ONLY = TRUE; // Set to true to only capture inserts
CREATE TASK mytask1
WAREHOUSE = mywh
SCHEDULE = '5 minute'
WHEN
SYSTEM$STREAM_HAS_DATA('MYSTREAM')
AS
INSERT INTO mytable1(id,name) SELECT id, name FROM mystream WHERE METADATA$ACTION = 'INSERT';
https://docs.snowflake.com/en/sql-reference/sql/create-task.html
https://docs.snowflake.com/en/sql-reference/sql/create-stream.html
Upvotes: 2
Reputation: 10079
There is no event source that can trigger a task; instead, a task runs on a schedule.
https://docs.snowflake.com/en/user-guide/tasks-intro.html#task-scheduling
So it's not possible to create an event based task scheduling for now.
Upvotes: 0