Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save gmirsky/ce2794fee44653c365b22f50dbfb7fe0 to your computer and use it in GitHub Desktop.

Select an option

Save gmirsky/ce2794fee44653c365b22f50dbfb7fe0 to your computer and use it in GitHub Desktop.
snowflake_reverse_engineer_warehouse_ddl
use role accountadmin;
--
-- create warehouse ddl
--
show warehouses;
--
CREATE temporary TABLE temp_warehouses as SELECT * FROM TABLE(RESULT_SCAN(LAST_QUERY_ID()));
--
select 'CREATE OR REPLACE WAREHOUSE ' || t."name" || '\n' ||
' INITIALLY_SUSPENDED = TRUE \n' ||
' SCALING_POLICY=' || '''' || t."type" || '''' || '\n' ||
' WAREHOUSE_SIZE=' || '''' || t."size" || '''' || '\n' ||
' MIN_CLUSTER_COUNT=' || t."min_cluster_count" || '\n' ||
' MAX_CLUSTER_COUNT=' || t."max_cluster_count" || '\n' ||
' AUTO_SUSPEND=' || t."auto_suspend" || '\n' ||
' AUTO_RESUME=' ||
case
when t."auto_resume" is null then 'False'
else t."auto_resume"
end || '\n' ||
case
when t."resource_monitor" is null then '--RESOURCE_MONITOR='
when t."resource_monitor" = 'null' then '--RESOURCE_MONITOR='
else ' RESOURCE_MONITOR=' || '''' || t."resource_monitor" || '''' || '\n'
end || '\n' ||
' COMMENT=' || '''' ||
case
when t."comment" is null then ''
else t."comment"
end || '''' || ';'
warehouse_ddl
from temp_warehouses t;
--
drop TABLE temp_warehouses;
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment