1

I want to fully overwrite a Redshift table.

In e.g. Hive, I could do the following:

INSERT OVERWRITE INTO target 
SELECT s.* FROM staging s LEFT JOIN target t
ON s.primaryKey = t.primaryKey AND s.distKey = t.distKey
WHERE t.primaryKey IS NULL;

I don't get this to work in Redshift (other than dropping and re-creating the table).

Does anybody know what the Redshift syntax is for overwrite?

1
  • last time I checked postgreql didn't have an overwrite clause of INSERT Commented Jun 29, 2016 at 12:08

1 Answer 1

5

While there is no command equivalent to INSERT OVERWRITE, you can do this via:

  • TRUNCATE <table>
  • Use SELECT INTO

eg: SELECT <column> INTO <table> FROM <etc>

The TRUNCATE command is a very efficient way to delete all contents of a table. However, it cannot be reversed by a ROLLBACK, so make sure you really want to do it!

See:

Sign up to request clarification or add additional context in comments.

1 Comment

Modern pg v9.5+ can use ON CONFLICT rules (example)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.