How to export data from Redshift database to a csv file

Use the ‘unload‘ command as shown below to extract data from Redshift database to a csv file.

unload ('SELECT * from schemaname.tablename')
TO 's3://bucketname/filename'
iam_role 'arn-of-iam-role'
CSV

See also  How to create an IAM role and attach it to the EC2 Instance