Re: Problem compiling function with BEGIN WORK; COMMIT WORK; - Mailing list pgsql-general

From Craig Ringer
Subject Re: Problem compiling function with BEGIN WORK; COMMIT WORK;
Date
Msg-id 4BD3ABC7.9010206@postnewspapers.com.au
Whole thread Raw
In response to Problem compiling function with BEGIN WORK; COMMIT WORK;  (Andre Lopes <lopes80andre@gmail.com>)
List pgsql-general
On 25/04/2010 9:07 AM, Andre Lopes wrote:
> Hi,
>
> I need to use the BEGIN WORK; and COMMIT WORK; to lock a table when I'am
> doing a SELECT and UPDATE operation.

PostgreSQL's server-side functions do *not* support transaction
management. They're functions that're used inside an existing transaction.

However, if you do not explcitly BEGIN a transaction before calling your
function, the statement your function runs in will start and stop its
own transaction. In other words, these two things are equivalent:

BEGIN;
SELECT my_function();
COMMIT;

and

SELECT my_function();

(outside an existing transaction)



Because your function is *always* inside a transaction, it can always
acquire locks and the like. It doesn't need to explicitly start a
transaction first.

--
Craig Ringer


pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: how to set CACHEDEBUG ?
Next
From: John Gage
Date:
Subject: Re: ISP provider with postgres and perl dbi