From: | Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at> |
---|---|
To: | "Medhavi Mahansaria *EXTERN*" <medhavi(dot)mahansaria(at)tcs(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Reg: PL/pgSQL commit and rollback |
Date: | 2015-03-17 14:03:44 |
Message-ID: | A737B7A37273E048B164557ADEF4A58B365A7E2B@ntex2010i.host.magwien.gv.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Medhavi Mahansaria wrote:
> I am writing a porting a procedure running in oracle to a PL/pgSQL function.
>
> I need to use commit and rollback in my function.
>
> I have read that usage of commit and rollback is not possible in PL/pgSQL, however savepoints can be
> used.
>
> even when i use savepoints and rollback to a savepoint in the exception block I am getting the
> following error
>
> ERROR: cannot begin/end transactions in PL/pgSQL
> HINT: Use a BEGIN block with an EXCEPTION clause instead.
Instead of explicitly using ROLLBACK, you have to code like this:
BEGIN
INSERT ... -- may cause an error
EXCEPTION
WHEN OTHERS
THEN ...
END
If you get into the exception block, PL/pgSQL will implicitly
have rolled back everything that happened between BEGIN and EXCEPTION.
Yours,
Laurenz Albe
From | Date | Subject | |
---|---|---|---|
Next Message | Medhavi Mahansaria | 2015-03-17 14:30:11 | Re: Reg: PL/pgSQL commit and rollback |
Previous Message | Ruth Melendo | 2015-03-17 14:01:30 | Re: pgpool + BDR, is it possible? |