[英]Calling a stored procedure using a task in Snowflake
I wrote a task that calls the procedure every weekend.我写了一个任务,每个周末调用该程序。
Here is my procedure that inserts the values into a table这是我将值插入表中的过程
CREATE OR REPLACE TABLE TABLE1(DATABASE_ VARCHAR, TABLE_ VARCHAR); // Table to store values
CREATE OR REPLACE PROCEDURE TASK_() //Procedure to insert values into table
RETURNS string
LANGUAGE JAVASCRIPT
AS
$$
var str = '';
var stmt = snowflake.createStatement({sqlText: "INSERT INTO TABLE1 VALUES ('DB1','TB1')"});
stmt.execute();
return str;
$$;
Here is my task that calls the above procedure every weekend.这是我每个周末调用上述程序的任务。
CREATE TASK mytask_hour
WAREHOUSE = COMPUTE_WH
SCHEDULE = 'USING CRON 0 0 * 1-12 SUN America/Los_Angeles'
TIMESTAMP_INPUT_FORMAT = 'YYYY-MM-DD HH24'
as
call TASK_();
But when I checked, the above task didn't run and the values were not inserted into the table.但是当我检查时,上面的任务没有运行,值也没有插入到表中。
So, I tried to debug my task and wrote a task that calls the above procedure every minute.因此,我尝试调试我的任务并编写了一个每分钟调用上述过程的任务。
create task mytask_hour
warehouse = COMPUTE_WH
schedule = '1 minute'
as
call TASK_();
Even this task didn't work.甚至这个任务也没有奏效。 Don't understand where I'm doing wrong
不明白我哪里做错了
Creating a task is not enough.创建任务是不够的。 The next step is to resume it as tasks are having the status "suspended" by default.
下一步是恢复它,因为任务默认处于“暂停”状态。
In your case the statement is在你的情况下,声明是
ALTER TASK mytask_hour resume;
Consequence: The tasks runs to your schedule.结果:任务按照您的计划运行。
On top of that you have to keep in mind that最重要的是,你必须记住
For more infos see here:https://docs.snowflake.com/en/sql-reference/sql/alter-task.html有关更多信息,请参见此处:https ://docs.snowflake.com/en/sql-reference/sql/alter-task.html
After creating a task, you must execute创建任务后,必须执行
ALTER TASK … RESUME
https://docs.snowflake.com/en/sql-reference/sql/create-task.html https://docs.snowflake.com/en/sql-reference/sql/create-task.html
I hope this helps...Rich我希望这有助于...丰富
ps If this (or another) answer helps you, please take a moment to "accept" the answer that helped by clicking on the check mark beside the answer to toggle it from "greyed out" to "filled in". ps 如果这个(或另一个)答案对您有帮助,请花点时间“接受”有帮助的答案,方法是单击答案旁边的复选标记,将其从“变灰”切换为“填充”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.