[英]Wanted to unload redshift table data to S3 with appending date on the file name
UNLOAD ('SELECT * FROM cn.test') TO 's3://bucket/archive/stage/test-#{format(@scheduledStartTime,'YYYY-MM-dd-HH')}.csv' credentials 'aws_access_key_id=###;aws_secret_access_key=###' DELIMITER '|' ADDQUOTES PARALLEL OFF ALLOWOVERWRITE
I tried the above command to unload to S3. 我尝试了上述命令将其卸载到S3。 Getting error : Amazon Invalid operation: syntax error at or near " YYYY
"; 得到错误:Amazon无效操作:“ YYYY
”或附近的语法错误; 1 statement failed. 1条语句失败。
If i give escape character near to date, the file name is going like test-# {format(@scheduledStartTime,'YYYY-MM-dd-HH')}.csv
instead of actual sysdate
. 如果我提供的转义字符接近日期,则文件名将类似于test-# {format(@scheduledStartTime,'YYYY-MM-dd-HH')}.csv
而不是实际的sysdate
。
Could anyone can help me 谁能帮我
A known issue. 一个已知问题。 I had similar requirements. 我有类似的要求。 As a resolution, I wrote a shell script with the unload
statement and when it executed successfully, I fired an mv
command to rename the file on the s3 bucket. 作为解决方案,我用unload
语句编写了一个shell脚本,当它成功执行时,我触发了一个mv
命令来重命名s3存储桶上的文件。
script: 脚本:
psql -U$user -h hostname -p port -c "unload (...) to 's3://bucket-name' credentials 'aws_access_key_id; aws_secret_access_key' [switch1][switch2]..."
if [ "$?" != "0" ]
then
echo "\nS3 Error: Error in unloading CSV to S3"
echo "\nS3 Error: Error in unloading CSV to S3" >> $log_file
else aws s3 mv s3://bucket-name/"$file_name".csv000 s3://bucket-name/"$file_name$from_date".csv
echo "$file_name$from_date successfully copied to s3" >> $status_file
return 0
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.