Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Amazon Redshift : drop table if exists

Writer Sebastian Wright

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.