0
votes

In Snowflake, you can use the get_ddl function like this to get ddl for tables, views and procedures:

select get_ddl('view', 'SOME_VIEW_I_CREATED')

But it doesn't seem you can do this with tasks.

Is there any way to easily get DDL for snowflake tasks?

NOTE: get_ddl is now supported in tasks in snowflake.

2

2 Answers

0
votes

NOTE: This is an old answer. The get_ddl() function now supports tasks.

Here's a script that will kind of generate the DDL you're looking for. It's not perfect but it's worked for my use cases thus far.

show tasks like '%';

SELECT concat('CREATE OR REPLACE TASK ',"name", chr(10)
              ,'    warehouse = ', "warehouse", chr(10)
              , case when "predecessor" is null then concat('    ,schedule = ''', "schedule",'''', chr(10)) else '' end
              ,'    ,STATEMENT_TIMEOUT_IN_SECONDS = 14400', chr(10)
              ,'    ,comment = ''', "comment",'''', chr(10)
              , case when "predecessor" is not null then concat('after ', "predecessor", chr(10)) else '' end
              ,'as',  chr(10)
              , "definition",';'
              ,chr(10),'alter task ',"name",' resume;') as T
FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
0
votes

As of at least 2019-12-24 (when I discovered it), you can now do this:

select get_ddl('task', 'demo_task')

In order to run this, you have to have the following permissions:

(USAGE on db & OWNERSHIP on schema & Any Permission on task) OR
(USAGE on db & USAGE on schema & Any Permission on task)