Re: Scripting issues

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: postgresql(at)bryden(dot)co(dot)za
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Scripting issues
Date: 2005-06-21 12:25:03
Message-ID: 20050621122503.GD28910@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jun 21, 2005 at 09:16:08 +0200,
postgresql(at)bryden(dot)co(dot)za wrote:

> 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

> 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.

If the script isn't running in a single transaction, consider just
dropping the table and ignoring any error messages.

If you do need to worry about a failed drop aborting a transaction, then
you can use savepoints in 8.0. However, it doesn't look like you can
have conditional rollbacks in psql until 8.1. So to use this feature
in a script you will need to write a function that traps the exception
and rolls back to the the savepoint for the case where the drop fails.

For pre 8.0 versions, consider having a function that checks the system
catalog before issuing the drop.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message FERREIRA, William (COFRAMI) 2005-06-21 12:42:00 compilation postgresql/solaris error
Previous Message Richard Huxton 2005-06-21 12:20:00 Re: problems with types after update to 8.0