Amazon Redshift
Database Developer Guide (API Version 2012-12-01)


Unloads the result of a query to one or more files on Amazon Simple Storage Service(Amazon S3), using Amazon S3 server-side encryption (SSE).


UNLOAD ('select-statement')
TO 's3://object-path/name-prefix'
[ WITH ] CREDENTIALS [AS] 'aws-auth-args' 
[ option [ ... ] ]

where option is

| DELIMITER [ AS ] 'delimiter-char' 
| FIXEDWIDTH [ AS ] 'fixedwidth-spec' }  
| BZIP2  
| GZIP     
| NULL [ AS ] 'null-string'
| PARALLEL [ { ON | TRUE } | { OFF | FALSE } ]



A SELECT query. The results of the query are unloaded. In most cases, it is worthwhile to unload data in sorted order by specifying an ORDER BY clause in the query; this approach saves the time required to sort the data when it is reloaded.

The query must be enclosed in single quotes as shown following:

('select * from venue order by venueid')


If your query contains quotes (enclosing literal values, for example), or backslashes (\), you need to escape them in the query text as shown following:

('select * from venue where venuestate=\'NV\'')
TO 's3://object-path/name-prefix'

The full path, including bucket name, to the location on Amazon S3 where Amazon Redshift will write the output file objects, including the manifest file if MANIFEST is specified. The object names are prefixed with name-prefix. For added security, UNLOAD connects to Amazon S3 using an HTTPS connection. By default, UNLOAD writes one or more files per slice. UNLOAD appends a slice number and part number to the specified name prefix as follows:


If MANIFEST is specified, the manifest file is written as follows:


UNLOAD automatically creates encrypted files using Amazon S3 server-side encryption (SSE). The COPY command automatically reads server-side encrypted files during the load operation. You can transparently download server-side encrypted files from your bucket using either the Amazon S3 management console or APIs. For more information, go to Protecting Data Using Server-Side Encryption.

To use Amazon S3 client-side encryption, specify the ENCRYPTED option.


The Amazon S3 bucket where Amazon Redshift will write the output files must reside in the same region as your cluster.

[WITH] CREDENTIALS [AS] 'aws-auth-args'

A clause that indicates the method your cluster will use for authentication and authorization to access the Amazon S3 bucket where UNLOAD will write the output files. Optionally, if you use the ENCRYPTED parameter, provide the encryption key in the aws-auth-args string.

The aws-auth-args string must not contain spaces.

The keywords WITH and AS are optional and are ignored.

You can specify either Role-Based Access Control or Key-Based Access Control. In either case, the IAM role or user must have the permissions required to access the specified AWS resources.


To protect your AWS credentials and sensitive data, we strongly recommend using role-based access control.

To specify role-based access control, provide the role ARN in the aws-auth-args string in the following format.


To specify key-based access control, provide the access key ID and the secret access key in the aws-auth-args string in the following format.


To further limit user access with key-based access control, you can provide temporary access credentials. For more information, see Temporary Security Credentials in Usage notes for the COPY command.

To encrypt your data files on Amazon S3 using client-side encryption, include the ENCRYPTED parameter and add the master symmetric encryption key to the aws-auth-args string in the following format. The master key must be a base-64 encoded symmetric key in 256-bit Advanced Encryption Standard (AES) format.

If the ENCRYPTED parameter is used, the aws-auth-args string is in the format, where <master-key> is the value of the master key that UNLOAD will use to encrypt the files.


For example, the following UNLOAD command uses role-based access control with an encryption key.

unload ('select * from venue')
to 's3://mybucket/unload/'

The following topics provide more details and examples of authentication options.


Creates a manifest file that explicitly lists the data files that are created by the UNLOAD process. The manifest is a text file in JSON format that lists the URL of each file that was written to Amazon S3. The manifest file is written to the same Amazon S3 path prefix as the unload files in the format <object_path_prefix>manifest. For example, if the UNLOAD specifies the Amazon S3 path prefix 's3://mybucket/venue_', the manifest file location will be 's3://mybucket/venue_manifest'.

DELIMITER AS 'delimiter_character'

Single ASCII character that is used to separate fields in the output file, such as a pipe character ( | ), a comma ( , ), or a tab ( \t ). The default delimiter is a pipe character. The AS keyword is optional. DELIMITER cannot be used with FIXEDWIDTH. If the data contains the delimiter character, you will need to specify the ESCAPE option to escape the delimiter, or use ADDQUOTES to enclose the data in double quotes. Alternatively, specify a delimiter that is not contained in the data.

FIXEDWIDTH 'fixedwidth_spec'

Unloads the data to a file where each column width is a fixed length, rather than separated by a delimiter. The fixedwidth_spec is a string that specifies the number of columns and the width of the columns. The AS keyword is optional. FIXEDWIDTH cannot be used with DELIMITER. Because FIXEDWIDTH does not truncate data, the specification for each column in the UNLOAD statement needs to be at least as long as the length of the longest entry for that column. The format for fixedwidth_spec is shown below:

'colID1:colWidth1,colID2:colWidth2, ...'


Specifies that the output files on Amazon S3 will be encrypted using Amazon S3 client-side encryption. For more information, see Unloading Encrypted Data Files. UNLOAD automatically creates encrypted files using Amazon S3 server-side encryption with AWS-managed encryption keys (SSE). UNLOAD does not support Amazon S3 server-side encryption with a customer-supplied key (SSE-C). To unload to encrypted compressed files, add the GZIP or BZIP2 option.


Unloads data to one or more bzip2-compressed files per slice. Each resulting file is appended with a .bz2 extension.


Unloads data to one or more gzip-compressed files per slice. Each resulting file is appended with a .gz extension.


Places quotation marks around each unloaded data field, so that Amazon Redshift can unload data values that contain the delimiter itself. For example, if the delimiter is a comma, you could unload and reload the following data successfully:

 "1","Hello, World" 

Without the added quotes, the string Hello, World would be parsed as two separate fields.

If you use ADDQUOTES, you must specify REMOVEQUOTES in the COPY if you reload the data.

NULL AS 'null-string'

Specifies a string that represents a null value in unload files. If this option is used, all output files contain the specified string in place of any null values found in the selected data. If this option is not specified, null values are unloaded as:

  • Zero-length strings for delimited output

  • Whitespace strings for fixed-width output

If a null string is specified for a fixed-width unload and the width of an output column is less than the width of the null string, the following behavior occurs:

  • An empty field is output for non-character columns

  • An error is reported for character columns


For CHAR and VARCHAR columns in delimited unload files, an escape character (\) is placed before every occurrence of the following characters:

  • Linefeed: \n

  • Carriage return: \r

  • The delimiter character specified for the unloaded data.

  • The escape character: \

  • A quote character: " or ' (if both ESCAPE and ADDQUOTES are specified in the UNLOAD command).


If you loaded your data using a COPY with the ESCAPE option, you must also specify the ESCAPE option with your UNLOAD command to generate the reciprocal output file. Similarly, if you UNLOAD using the ESCAPE option, you will need to use ESCAPE when you COPY the same data.


By default, UNLOAD fails if it finds files that it would possibly overwrite. If ALLOWOVERWRITE is specified, UNLOAD will overwrite existing files, including the manifest file.


By default, UNLOAD writes data in parallel to multiple files, according to the number of slices in the cluster. The default option is ON or TRUE. If PARALLEL is OFF or FALSE, UNLOAD writes to one or more data files serially, sorted absolutely according to the ORDER BY clause, if one is used. The maximum size for a data file is 6.2 GB. So, for example, if you unload 13.4 GB of data, UNLOAD creates the following three files.

s3://mybucket/key000    6.2 GB
s3://mybucket/key001    6.2 GB
s3://mybucket/key002    1.0 GB


The UNLOAD command is designed to use parallel processing. We recommend leaving PARALLEL enabled for most cases, especially if the files will be used to load tables using a COPY command.

Usage Notes

Using ESCAPE for All Delimited UNLOAD Operations

When you UNLOAD using a delimiter and there is any possibility that your data includes the delimiter or any of the characters listed in the ESCAPE option description, you must use the ESCAPE option with the UNLOAD statement. If you do not use the ESCAPE option with the UNLOAD, subsequent COPY operations using the unloaded data might fail.


We strongly recommend that you always use ESCAPE with both UNLOAD and COPY statements unless you are certain that your data does not contain any delimiters or other characters that might need to be escaped.

Loss of Floating-Point Precision

You might encounter loss of precision for floating-point data that is successively unloaded and reloaded.

Limit Clause

The SELECT query cannot use a LIMIT clause in the outer SELECT. For example, the following UNLOAD statement will fail:

unload ('select * from venue limit 10') 
to 's3://mybucket/venue_pipe_' credentials 

Instead, use a nested LIMIT clause. For example:

unload ('select * from venue where venueid in 
(select venueid from venue order by venueid desc limit 10)') 
to 's3://mybucket/venue_pipe_' credentials 

Alternatively, you could populate a table using SELECT…INTO or CREATE TABLE AS using a LIMIT clause, then unload from that table.