Redshift : Redshift Unload getting the file as filename appended with 000 – how to get as actual filename.

AWS Redshift @ Freshers.in

Unfortunately, Redshift’s UNLOAD command appends a part number (like 000) to the output file names by default, and there’s no built-in way to change this behavior. Even when you set PARALLEL OFF, Redshift still appends the part number to the output file name.

However, you can work around this by using an external process to rename the file after it’s been unloaded. If you are using AWS S3 as the destination for the UNLOAD command, you can use the AWS CLI or SDKs to rename the file to your desired format.

Here’s an example using the AWS CLI:

  1. Unload your data from Redshift to S3:
UNLOAD ('SELECT * FROM freshers_table')
TO 's3://freshers-bkt/freshers-in-path/prefix_'
IAM_ROLE 'arn:aws:iam::freshers-in-account-id:role/freshers-in-role-name'
FORMAT AS CSV
PARALLEL OFF;
  1. Rename the file using the AWS CLI:

First, install the AWS CLI if you haven’t already: https://aws.amazon.com/cli/

Then, run the following command to copy the file with the desired name and delete the original file:

aws s3 mv s3://freshers-bkt/freshers-in-path/prefix_000 s3://<code class="language-sql">freshers-bkt/freshers-in-path/final_file_name.csv 
This command will “rename” the file by copying it to the new desired name and deleting the original file with the 000 suffix.

Keep in mind that you’ll need to have the appropriate permissions for the S3 bucket and objects involved in this process.

Author: user

Leave a Reply