Amazon Redshift : drop table if exists

Attilah picture Attilah · Nov 24, 2013 · Viewed 16.4k times · Source

Does Redshift support any statement equivalent to the following?

DROP TABLE IF EXISTS tablename

Answer

mark.monteiro picture mark.monteiro · Oct 29, 2014

This is supported in the latest version of Redshift:

DROP TABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]

IF EXISTS Clause that indicates that if the specified table doesn’t exist, the command should make no changes and return a message that the table doesn't exist, rather than terminating with an error.

This clause is useful when scripting, so the script doesn’t fail if DROP TABLE runs against a nonexistent table.

Taken from online AWS Redshift docs.