Does Redshift support any statement equivalent to the following?
DROP TABLE IF EXISTS tablename
Does Redshift support any statement equivalent to the following?
DROP TABLE IF EXISTS tablename
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.
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.