Thread: commit inside a function failing

commit inside a function failing

From
Suresh Raja
Date:
Hi All:

We are running a function with a loop in it. We tried 
commit;
We are getting error with above command.   How can i easily commit withing a function.


Thanks,
-SR 

Re: commit inside a function failing

From
Pavel Stehule
Date:
Hi

2015-01-23 20:56 GMT+01:00 Suresh Raja <suresh.rajaabc@gmail.com>:
Hi All:

We are running a function with a loop in it. We tried 
commit;
We are getting error with above command.   How can i easily commit withing a function.


It is not possible in PostgreSQL

Regards

Pavel Stehule
 

Thanks,
-SR 

Re: commit inside a function failing

From
Adrian Klaver
Date:
On 01/23/2015 11:56 AM, Suresh Raja wrote:
> Hi All:
>
> We are running a function with a loop in it. We tried
> commit;
> We are getting error with above command.   How can i easily commit
> withing a function.

Functions do not have transactions inside them. If you are using plpgsql
you can use EXCEPTIONS:

http://www.postgresql.org/docs/9.3/interactive/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING
>
>
> Thanks,
> -SR


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: commit inside a function failing

From
"ktm@rice.edu"
Date:
On Fri, Jan 23, 2015 at 01:56:53PM -0600, Suresh Raja wrote:
> Hi All:
>
> We are running a function with a loop in it. We tried
> commit;
> We are getting error with above command.   How can i easily commit withing
> a function.
>
>
> Thanks,
> -SR

PostgreSQL functions run within a transaction. You would need to use
something like db_link.

Regards,
Ken


Re: commit inside a function failing

From
Christopher Browne
Date:
<p dir="ltr">The straightforward answer is that stored functions always run *inside* the context of a preexisting
transaction,therefore you cannot request a separate transaction from within a stored function.<p dir="ltr">What you are
askingis fairly deeply impossible.