Ilja
Ilja

Reputation: 1053

S3 to Redshift using COPY: Cannot COPY into nonexistent table

I'm new to Redshift & S3.

I try to save data to S3 and retrieve it. While saving to S3 works, retrieving returns error:

saving

UNLOAD ('SELECT 5 as field')
TO 's3://my_bucket/test_001/example_1'
-- identification --
REGION 'us-east-1'
HEADER
ALLOWOVERWRITE
CSV

--> worked


retrieving

COPY example_1  FROM 's3://my_bucket/test_001/' 
-- same identification as above -- 
CSV

--> returns error INTERNAL_ERROR :: [Amazon](500310) Invalid operation: Cannot COPY into nonexistent table example_1

What am I doing wrong? AFAIK I followed this documentation

Upvotes: 1

Views: 3924

Answers (1)

Bill Weiner
Bill Weiner

Reputation: 11032

The table you are COPYing into needs to exists before the COPY command is run - in your case the table "example_1". This can be done in a number of ways but direct way is with CREATE TABLE command. Since you just want to store a single column with what I assume is an integer value just run

CREATE TABLE example_1 (A INT); 

before you run the COPY command.

Upvotes: 2

Related Questions