Sourav Gupta
Sourav Gupta

Reputation: 257

Use of column names in Redshift COPY command which is a reserved keyword

I have a table in redshift where the column names are 'begin' and 'end'. They are Redshift keywords. I want to explicitly use them in the Redshift COPY command. Is there a workaround rather than renaming the column names in the table. That will be my last option.

I tried to enclose them within single/double quotes, but looks like the COPY command only accepts comma separated column names.

Upvotes: 3

Views: 3212

Answers (1)

Red Boy
Red Boy

Reputation: 5729

Copy command works fails if you don't escape keywords as column name. e.g. begin or end.

copy test1(col1,begin,end,col2) from 's3://example/file/data1.csv' credentials 'aws_access_key_id=XXXXXXXXXXXXXXX;aws_secret_access_key=XXXXXXXXXXX' delimiter ',';

ERROR: syntax error at or near "end"

But, it works fine if as begin and end are enclosed by double quote(") as below.

copy test1(col1,"begin","end",col2) from 's3://example/file/data1.csv' credentials 'aws_access_key_id=XXXXXXXXXXXXXXX;aws_secret_access_key=XXXXXXXXXXX' delimiter ',';

I hope it helps. If there is some different error please update your question.

Upvotes: 3

Related Questions