Reputation: 870
I have a stored procedure which unloads data from table into a Azure blob container. The conditions of file unloading is the file should be unloaded into a date time partition folder.
2022-06-09/1651011730.067872/FileName.csv
I have written the following stored procedure:
execute immediate
$$
declare
date_partition varchar;
date_time_partition varchar;
begin
set date_partition = '2022-06-09';
set date_time_partition = '1651011730.067872';
COPY INTO @STAGE/:datetime/:date_time_partition/filename
FROM (
select * from table
where ID = 1
) file_format = CSV_FORMAT HEADER = TRUE DETAILED_OUTPUT = TRUE overwrite = true;
return date_partition;
end;
$$;
The problem I am facing is the data is getting on loaded in this format
date_partition/date_partition/FileName.csv
What can I do to use the variables in the COPY INTO command?
Upvotes: 1
Views: 1747
Reputation: 4578
Something like works for me:
execute immediate
$$
declare
date_partition varchar default '2022-06-09';
date_time_partition varchar default '1651011730.067872';
copy_into varchar default 'COPY INTO @~/' || date_partition || '/' || date_time_partition || '/filename FROM (select * from citibike_trips limit 10) file_format = MYCSV HEADER = TRUE DETAILED_OUTPUT = TRUE overwrite = true';
begin
execute immediate :copy_into;
return date_partition;
end;
$$;
When I list the stage I see:
2022-06-09/1651011730.067872/filename_0_0_0.csv.gz
Is this what you're looking for?
Upvotes: 2