Update:
Now Redshift supports DROP TABLE with IF EXISTS clause. http://docs.aws.amazon.com/redshift/latest/dg/r_DROP_TABLE.html
Since Redshift didn't support DROP TABLE IF EXISTS
, we were handling it by getting existing table names.
To get table names on Redshift, I'm using pg_table_def
table. For example, I run the following sql to get all table names excluding system tables.
SELECT
schemaname, tablename
FROM
pg_table_def
WHERE
schemaname <> 'pg_catalog'
AND schemaname <> 'information_schema'
AND schemaname !~ '^pg_toast'
GROUP BY
schemaname,tablename;
Here is a sample result.
schemaname | tablename
------------+-----------
my_schema | access_log
my_schema | error_log
my_schema | vmstats_log
public | users
public | groups
See the following link for the details.