How to unload and copy data in Redshift

unload ('SELECT * from schemaname.tablename')
TO 's3://bucketname/filename'
credentials 'aws_access_key_id=XXXXXX;aws_secret_access_key=XXXXX'
DELIMITER '|'
allowoverwrite
ESCAPE;
copy schemaname.tablename
from 's3://bucketname/filename'
credentials 'aws_access_key_id=XXXXXX;aws_secret_access_key=XXXXX'
DELIMITER '|'
ESCAPE;
See also  How to create a view in Redshift database