Re: Support for idempotent schema changes? - Mailing list pgsql-general

From Florian G. Pflug
Subject Re: Support for idempotent schema changes?
Date
Msg-id 45ECEE1A.90208@phlo.org
Whole thread Raw
In response to Re: Support for idempotent schema changes?  ("Joshua D. Drake" <jd@commandprompt.com>)
List 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

pgsql-general by date:

Previous
From: Robert Treat
Date:
Subject: Re: giving a user permission to kill their processes only
Next
From: "Reuven M. Lerner"
Date:
Subject: Database slowness -- my design, hardware, or both?