1
votes

I am trying to load a csv file ins s3 into redshift using aws copy command in lambda. The problem is i have more columns in csv than in redshift table. so whenever i trigger lambda fnction i get the error "Extra columns found"

how to load specific columns from csv

my csv files is of form

year, month, description, category,SKU, sales(month)

and my redshift table is of form

year month description category SKU
-----------------------------------

my copy command is as follows

COPY public.sales 
FROM 's3://mybucket/sales.csv' 
iam_role 'arn:aws:iam::99999999999:role/RedShiftRole' 
delimiter ',' 
ignoreheader 1 
acceptinvchars
1

1 Answers

1
votes

You can specify the list of columns to import into your table - see COPY command documentation for more details.

COPY public.sales (year, month, description, category, SKU)
FROM 's3://mybucket/sales.csv' 
iam_role 'arn:aws:iam::99999999999:role/RedShiftRole' 
delimiter ',' 
ignoreheader 1 
acceptinvchars