Re: conditionally executing migration code

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "Michael P(dot) Soulier" <michael_soulier(at)mitel(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: conditionally executing migration code
Date: 2008-06-05 20:13:06
Message-ID: dcc563d10806051313g344ce1b3i28980068c33268be@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Can't you just try to add the column and catch the error? If you're
in a transaction use a user defined function to run it an catch the
exception in pl/pgsql.

On Thu, Jun 5, 2008 at 12:15 PM, Michael P. Soulier
<michael_soulier(at)mitel(dot)com> wrote:
> I'm using some simple migration code to execute individual fragments of SQL
> code based on the version of the schema. Is there a way to perform an ALTER
> TABLE conditionally?
>
> Example:
>
> I want to add column foo to table bar, but only if column foo does not exist
> already.
>
> I'm trying to avoid such situations, but it's not always easy.
>
> Thanks,
> Mike
> --
> Michael P. Soulier <michael_soulier(at)mitel(dot)com>, 613-592-2122 x2522
> "Any intelligent fool can make things bigger and more complex... It
> takes a touch of genius - and a lot of courage to move in the opposite
> direction." --Albert Einstein
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2008-06-05 21:50:57 Re: Annoying messages when copy sql code to psql terminal
Previous Message Marco Bizzarri 2008-06-05 19:37:05 Re: Temporary Tables and Web Application