Skip site navigation (1) Skip section navigation (2)

Re: Transaction manipulation commands in user defined c functions?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Hadjivassiliou <sporegnosis(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Transaction manipulation commands in user defined c functions?
Date: 2010-06-09 16:14:47
Message-ID: 26206.1276100087@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
Michael Hadjivassiliou <sporegnosis(at)gmail(dot)com> writes:
> I've been searching for a way to do transaction blocks and savepoints within
> a user defined c function. Apparently the docs state that if an SPI function
> throws an error, control goes out of the function and the current
> transaction is rolled back, yet it hints that you can do subtransactions
> within a c function.

Well, sure.  Look at the way that plpgsql implements a BEGIN/EXCEPTION
block, for example.  You need to establish a subtransaction and have
a TRY/CATCH block to catch the error and clean up.

But having said that ... it's pretty messy and I wonder why you are
wanting to do this in a C function.  Your code would be a lot more
future-proof in plpgsql, say.  And if you're invoking operations as
heavyweight as a subtransaction, you're certainly not going to get any
noticeable performance win from using C.

			regards, tom lane

In response to

Responses

pgsql-novice by date

Next:From: Michael HadjivassiliouDate: 2010-06-09 20:24:08
Subject: Re: Transaction manipulation commands in user defined c functions?
Previous:From: coviolo@libero.itDate: 2010-06-09 15:23:36
Subject: Re: problem with variable

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group