From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Alexander Farber <alexander(dot)farber(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Does RAISE EXCEPTION rollback previous commands in a stored function? |
Date: | 2016-03-02 10:10:33 |
Message-ID: | CAFj8pRCJ1RkfZ3e44eQ3EKAe5rySfjAR-rbKHePVVkkMSzV8iQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi
2016-03-02 10:47 GMT+01:00 Alexander Farber <alexander(dot)farber(at)gmail(dot)com>:
> Hi Laurenz,
>
> how to set such a savepoint inside of a stored function?
>
> Can I call "START TRANSACTION", and then at some point later in the same
> stored function call RAISE EXCEPTION?
>
You cannot to do it explicitly. But, when you handle any exception in bloc,
then subtransaction is used implicitly
BEGIN ~ starts transaction
...
...
EXCEPTION WHEN ... ~ rollback transaction
END -- commit transaction when no exception
http://www.postgresql.org/docs/9.1/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING
Regards
Pavel
>
> Regargs
> Alex
>
> On Wed, Mar 2, 2016 at 10:37 AM, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
> wrote:
>
>> Andreas Kretschmer wrote:
>> >> Alexander Farber <alexander(dot)farber(at)gmail(dot)com> hat am 1. März 2016 um
>> 19:41
>> >> geschrieben:
>>
>
>
>> >> in PostgreSQL 9.5 does RAISE EXCEPTION reliably rollback all previous
>> >> commands in a stored function?
>> >
>> > Yes.
>>
>> That is, unless you set a savepoint to which you can rollback.
>>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Albe Laurenz | 2016-03-02 10:18:33 | Re: Does RAISE EXCEPTION rollback previous commands in a stored function? |
Previous Message | Vitaly Burovoy | 2016-03-02 10:09:14 | Re: How to ensure that a stored function always returns TRUE or FALSE? |