commit inside a function failing

Started by Suresh Rajaabout 11 years ago5 messagesgeneral
Jump to latest
#1Suresh 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.

Thanks,
-SR

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Suresh Raja (#1)
Re: [SQL] commit inside a function failing

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

Show quoted text

Thanks,
-SR

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Suresh Raja (#1)
Re: commit inside a function failing

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

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

#4Kenneth Marshall
ktm@rice.edu
In reply to: Suresh Raja (#1)
Re: [SQL] commit inside a function failing

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

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#5Christopher Browne
cbbrowne@sympatico.ca
In reply to: Kenneth Marshall (#4)
Re: commit inside a function failing

<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>
<p dir="ltr">What you are asking is fairly deeply impossible.</p>