在 Snowflake 任务中执行多行

Executing Multiple Lines in a Snowflake Task

我创建了下面的任务,但无法让它执行所有行。看起来它只是从 productweekly_upload 中执行第一次删除然后完成。有人有想法么?这是我第一次使用任务

CREATE OR REPLACE TASK WeeklySymphony_Load
  WAREHOUSE = UPLOADWAREHOUSE
  SCHEDULE = 'USING CRON 10 8 * * MON America/New_York'
as

--run every monday at 8:10 am 

delete from Productweekly_Upload;
delete from Factsweekly_Upload;
delete from Productweekly;
delete from Factsweekly;

copy into ProductWeekly_Upload
from @symphony_s3_stage/prasco_phast_it_prdct_wk_;

copy into FactsWeekly_Upload
from @symphony_s3_stage/prasco_phast_it_wk_;

insert into ProductWeekly
select * from ProductWeekly_Upload;

insert into FactsWeekly 
select * from FactsWeekly_Upload;

您只能在一个任务中执行 1 个命令。如果你想创建多个步骤,你可以将它们包装到一个存储过程中并从 TASK 调用 SP,或者你可以将每个步骤创建为一个 TASK 并建立这些依赖关系,以便它们按顺序执行。

我建议通读此文档:

https://docs.snowflake.com/en/user-guide/tasks-intro.html

如果你想要多语句,3种解决方案是:

  1. 存储过程
  2. 链式多任务处理 AFTER 语句
  3. 将过程逻辑与 AS DECLARE // BEGIN // END 结合使用;堵塞 https://docs.snowflake.com/en/sql-reference/sql/create-task.html#procedural-logic-using-snowflake-scripting