Redshift Copy Command

Redshift Çağrı ŞİŞMAN 26.7.2017

You can use copy command to load data into a Redshift table from a file or an Amazon DynamoDb table. Amazon S3 bucket can be used to store files.

Copy Command Syntax

copy tablename 
from 's3 file path' 
access_key_id 'accesskeyid'
secret_access_key 'secretaccesskey' json 'auto';

tablename: The name of the target Redshift table. Table must exists in database.

s3 file path: Location path of data files.

accesskeyid: S3 Bucket Access Key  ID

secrettaccesskey: S3 Bucket Secret Access Key

You can load data in csv or json format. 'auto' means that data mapping will be automatic by json data field names to Redshift table columns. The mapping is case-sensitive.  Column names in Redshift tables are always lowercase, so when you use the ‘auto’ option, matching json field names must also be lowercase.

If you get error while loading data you can look details of errors using below query.

select le.starttime, d.query, d.line_number, d.colname, d.value,
le.raw_line, le.err_reason    
from stl_loaderror_detail d, stl_load_errors le
where d.query = le.query
order by le.starttime desc
limit 100