I have been using UNLOAD
statement in Redshift for a while now, it makes it easier to dump the file to S3
and then allow people to analysie.
The time has come to try to automate it. We have Amazon Data Pipeline
running for several tasks and I wanted to run SQLActivity
to execute UNLOAD
automatically. I use SQL
script hosted in S3
.
The query itself is correct but what I have been trying to figure out is how can I dynamically assign the name of the file. For example:
UNLOAD('<the_query>')
TO 's3://my-bucket/' || to_char(current_date)
WITH CREDENTIALS '<credentials>'
ALLOWOVERWRITE
PARALLEL OFF
doesn't work and of course I suspect that you can't execute functions (to_char
) in the "TO
" line. Is there any other way I can do it?
And if UNLOAD
is not the way, do I have any other options how to automate such tasks with current available infrastructure (Redshift
+ S3
+ Data Pipeline
, our Amazon EMR
is not active yet).
The only thing that I thought could work (but not sure) is not instead of using script, to copy the script into the Script
option in SQLActivity
(at the moment it points to a file) and reference {@ScheduleStartTime}