Re: Scripting issues

From: Richard Huxton <dev(at)archonet(dot)com>
To: postgresql(at)bryden(dot)co(dot)za
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Scripting issues
Date: 2005-06-21 08:16:15
Message-ID: 42B7CCCF.80705@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

postgresql(at)bryden(dot)co(dot)za wrote:
> Hi
>
> I come from a MSSQL background and am trying to figure out how to write
> deployment scripts for PostgreSQL. Typically, if I want to drop a
> function, I would write a script that first checks for it's existence and
> then performs the drop.
>
> In MSSQL it would be as easy as (this can be done in native TSQL):
> IF EXISTS (...some query to system tables...)
> DROP function XXX
>
> However, I am really strugling to understand how to do this in PostgreSQL.
> It seem the standard SQL language doesn't support the IF statement.
>
> All the development that I do needs to be deployed in a script fashion and
> generally I need to check for the existence of an object before replacing
> or dropping.
>
> Any help will be much appreciated.

It's simple enough to write a plpgsql function that takes two text
parameters - execute the first and see if any rows are returned, then
execute the second if any rows were.

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message postgresql 2005-06-21 08:59:58 Re: Scripting issues
Previous Message Richard Huxton 2005-06-21 08:14:56 Re: HELP!!! Corrupt Database!