Amazon Redshift : drop table if exists

Does Redshift support any statement equivalent to the following?

DROP TABLE IF EXISTS tablename 

2 Answers

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.

0

See next answer; this is out of date.

Support for

DROP TABLE IF EXISTS tablename; 

was added in PostgreSQL 8.2. Redshift is a very heavily modified fork of 8.1 by ParAccel, and as far as I know they've backported very few changes from newer versions. It's very unlikely that it supports IF EXISTS; you probably need to do a catalog query to determine if the table exists by looking up information_schema, then deciding whether you'll create it based on the result.

1

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoaWlpZm6FcoKOmqSasp%2BjerOxw6yfop6kYrGzu89mq5qanJp6qrKMnq%2Biq6So