Search code examples
sqlamazon-redshiftddl

Redshift: add column if not exists


The following works in Postgres 9.6 but not in Redshift:

ALTER TABLE stats
    ADD COLUMN IF NOT EXISTS panel_exit timestamp;

Can the same functionality be achieved in Redshift?


Solution

  • There is no Amazon Redshift command equivalent to ADD COLUMN IF NOT EXISTS.

    See: ALTER TABLE documentation

    To replicate this functionality, your application would first need to query the table metadata and then make the decision whether to issue the ADD COLUMN command.