2
votes

What is the simplest way to drop all tasks in Snowflake under a specific schema? I'm hoping this won't require some sort of Javascript loop.

I'm hoping for something like ... :)

DROP ALL TASKS IN <SCHEMA>

Going through it one by one can be cumbersome.

Did not see anything in the documentation that alluded to this: https://docs.snowflake.com/en/sql-reference/sql/drop-task.html

2

2 Answers

3
votes

You can use the show tasks, followed by a select statement to generate the DDL you can then run as a SQL script.

use database "mydatabase";
use schema "myschema";    
show tasks;
SELECT 'DROP TASK ' || "name" || ';' FROM  table(result_scan(last_query_id()));
1
votes

I had exactly the same requirement once. I ended up with:

-- SHOW TASKS IN SCHEMA ...;
SHOW TASKS IN DATABASE;

SELECT LISTAGG(REPLACE('DROP TASK IF EXISTS <TASK_NAME>;' || CHAR(13),
                      '<TASK_NAME>'
                      ,CONCAT_WS('.', "database_name","schema_name", "name"))
               ,'')  AS drop_all_task_script
FROM TABLE(result_scan(last_query_id()));