Re: Support for idempotent schema changes?

From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: David Lowe <dlowe(at)airplay(dot)com>, pgsql-general(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Support for idempotent schema changes?
Date: 2007-03-06 04:29:14
Message-ID: 45ECEE1A.90208@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joshua D. Drake wrote:
> David Lowe wrote:
>> Within the context of a script, executing:
>>
>> Begin
>> Statement1
>> Statement2
>> Statement3
>> Commit
>>
>> Where I only wish to commit if the error is specific to the object
>> already existing, and rollback for all other errors, what's the best way
>> to accomplish that?
>>
> You would have to put each statement into a savepoint, and catch each
> error that occured and commit or rollback to a savepoint
> based on that result.

You could write a plpgsql function that executes a text given to it
as a parameter, and catches only "already exists" errors. Then your
schema script could look like
select execute_ignoreexists('create table ...') ;
select execute_ignoreexists('create index ...') ;
...

greetings, Florian Pflug

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Reuven M. Lerner 2007-03-06 04:31:03 Database slowness -- my design, hardware, or both?
Previous Message Robert Treat 2007-03-06 04:26:13 Re: giving a user permission to kill their processes only