Re: SET TRANSACTION on pl/pgSQL function

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "gianni(dot)zammarchi(at)tiscali(dot)it" <gianni(dot)zammarchi(at)tiscali(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SET TRANSACTION on pl/pgSQL function
Date: 2006-03-02 00:29:34
Message-ID: 20060302002934.GA84292@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Mar 02, 2006 at 12:34:25AM +0100, gianni(dot)zammarchi(at)tiscali(dot)it wrote:
> I have a little problem, I am working with postgres 8.1.2 and I am
> creating some store procedure, I would like to handle inside to them
> the commit and rollback functionality, but If I entry commit command I
> am not able to exceute the funciotn anymore.

PostgreSQL functions are executed in the context of an outer
transaction so they can't issue COMMIT or ROLLBACK statements.
However, in 8.0 and later, several languages (e.g., PL/pgSQL)
support error trapping, effectively providing savepoint and
rollback to savepoint capability.

http://www.postgresql.org/docs/8.1/interactive/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

One way around this restriction would be for the function to use
dblink to make another connection to the database; the server-side
function then becomes a database client. The function could execute
transaction-starting and -ending commands over that connection.

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Maclean 2006-03-02 00:39:01 Re: Special offer with a possible dontation to the project
Previous Message Chris Travers 2006-03-02 00:13:59 Re: Need a GNU SQL CLI tool for Win32 with ODBC support.