Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
Redshift Unload to S3 Location that is a Concatenated String

I'm trying to unload the results from a redshift query to a bucket folder that is yesterday's date.

So in the below example the data should be in s3://mybucket/reporting/20170321/myreport-000

unload ('select * from #my_report')
to 's3://mybucket/reporting/' || replace(trunc(current_date - 1),'-','') || '/myreport'
credentials 'aws_access_key_id=key;aws_secret_access_key=secretkey'
delimiter ','
gzip addquotes null as ''
PARALLEL off
allowoverwrite;

However I get the error

[Amazon](500310) Invalid operation: syntax error at or near "||";

Does the string concatenation not evaluate first?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It's not possible to dynamically build the UNLOAD path statement.

Two methods I can suggest:

  • Method 1: I would suggest writing a shell script/Python/Javascript where you can create variables, then pass in those variables into a connection's statement-query.
  • Method 2: Or you can use RedshiftCopyActivity in AWS Data Pipeline to copy from Redshift to S3. Input is RedshiftDataNode and output is S3DataNode where you can specify expression for directoryPath.

    If I’ve made a bad assumption please comment and I’ll refocus my answer.
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!