I am new to javascript and snowflake uses js like syntax in stored procedures.
I am trying to create dynamic SQL so that it loops between start_date to end_date to copy into from different s3 folders based on dates
CREATE PROCEDURE load_dynamic_s3path_to_table(begin_date strings, end_date strings)
AS
$$
var stmt = snowflake.createStatement(
{sqlText: "copy into table from s3://test/2020-01-01/"}
);
var rs = stmt.execute();
$$;
Based on the date parameters in the stored procedure, for example begin_date 2020-01-01, end_date 2020-01-03.
I want to execute the copy into commands 3 times;
copy into table from s3://test/2020-01-01/
copy into table from s3://test/2020-01-02/
copy into table from s3://test/2020-01-03/
I imagine the pseudo code to be something like this:
CREATE PROCEDURE load_dynamic_s3path_to_table(begin_date strings, end_date strings)
AS
$$
var dates = begin_date
while date(dates)>=date(begin_date) and date(dates)<date(end_date)
var stmt = snowflake.createStatement(
{sqlText: "copy into table from s3://test/" + dates}
);
var rs = stmt.execute();
dates+=1
$$;
Could anyone help turn the pseudo code into the right js syntax and executable in snowflake?
Thank you!
question from:
https://stackoverflow.com/questions/65881058/how-to-loop-through-date-string-parameter-in-javascript-stored-procedure-snowfla 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…