Wed. Nov 25th, 2020
snowflake

Tasks in snowflake are handy to execute SQL or javascript code or stored procedure on your DB periodically or based on specific events, Tasks can also be used independently to generate periodic reports

Create a simple SQL task ( non scheduled )

create task MyTask1 WAREHOUSE = COMPUTE_WH as (select * from test1);

Create a simple Task scheduled every morning 9 am, LA time.

create task MyTASK2 SCHEDULE = 'USING CRON 0 9 * * * America/Los_Angeles' WAREHOUSE = COMPUTE_WH as (select * from test1);

Create a simple Task scheduled every 2 minutes :

CREATE TASK mytask_minute
  WAREHOUSE = mywh
  SCHEDULE = '2 MINUTE'
AS
INSERT INTO mytable(ts) VALUES(CURRENT_TIMESTAMP);

By default, all tasks are suspended once created, to enable them, you will need to resume them.

display all tasks :

Show tasks;

ALTER TASK task_one RESUME;

If you wish to run Task MyTask4 after Task Root (MyTASK2 ), root ( MyTASK2 ) needs to be suspended first :

ALTER TASK MyTASK2 SUSPEND;
create task MyTask4 WAREHOUSE = COMPUTE_WH after MyTASK2 as (select * from test1) ;

Resume all dependent tasks that are children of a root task with a case-insensitive name:

select system$task_dependents_enable('test.PUBLIC.MyTASK2');

By Amine Hallam

Author & blogger on the latest data analytics technologies: Hadoop, Snowflake, Cloud ( AWS ), ETL .. etc

Leave a Reply

Your email address will not be published. Required fields are marked *