Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redshift copy command append, replace or upsert?

Suppose I run the Redshift COPY command for a table where existing data. Then does the command:

  1. Appends the data to the existing table?
  2. Wipes clean existing data and add the new data?
  3. Upserts the data. i.e., UPDATE if data with the same primary key is present in table or INSERT otherwise
like image 949
Pavan Kumar Avatar asked Jun 12 '26 02:06

Pavan Kumar


2 Answers

The COPY command always appends data to a table.

like image 103
John Rotenstein Avatar answered Jun 17 '26 06:06

John Rotenstein


In order to effectively upsert in Redshift using "copy" command, you need first to load your data (from your copy) to a staging table then run some sql on redshift to process this data.

AWS have documented an approach here https://docs.aws.amazon.com/redshift/latest/dg/t_updating-inserting-using-staging-tables-.html

like image 26
Jon Scott Avatar answered Jun 17 '26 07:06

Jon Scott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!