I want to create a task that executes a copy command every minute in snowflake, the problem is that the path of the file that needs to be taken (the files are stored as parquet files in s3), it is determined by the current date, for that I have this code:
SET date_pattern = CONCAT('CALLS/', TO_CHAR(CURRENT_DATE(), 'YYYY/MM/DD'), '/', '*.parquet');
create or replace task sv_task_copy_command_trial
warehouse = compute_wh
schedule = '1 MINUTE'
AS
copy into expose_sf_data_trial.decoded.CALLS_COPY_COMMAND
from (select $1:LOAD_ID::varchar::TIMESTAMP_LTZ,
$1:TIMESTAMP::timestamp
from @expose_sf_data_trial.decoded.trial_calls_copy_command)
pattern='<date_pattern>';`
First a set the variable date_pattern and pass it into pattern value for the copy command (SF doesn't allow dynamic variables in the copy command, so it is not possible to unify this code).
So my question here is, how can I create a task for this? I will need the date_pattern to be created in the same session as the copy command it is going to be executed, otherwise this variable won't have any value.
The workaround I'm trying to do is create a task that executes both queries, first the set of the date_pattern and then the copy command. I've already checked the documentation and suggests the SP but I'd like to explore other ideas.
Thanks a lot for your time :)