17

Does Redshift support any statement equivalent to the following?

DROP TABLE IF EXISTS tablename
4

2 回答 2

27

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.

于 2014-10-29T00:54:22.213 回答
19

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.

于 2013-11-24T01:40:44.487 回答