Обсуждение: ROLLBACK in a function?

Поиск
Список
Период
Сортировка

ROLLBACK in a function?

От
Rory Campbell-Lange
Дата:
I understand that functions provide an implied transaction in
PostgreSQL. Does that mean one can ROLLBACK/COMMIT within the body of a
function?

Rory
--
Rory Campbell-Lange
<rory@campbell-lange.net>
<www.campbell-lange.net>

Re: ROLLBACK in a function?

От
Doug McNaught
Дата:
Rory Campbell-Lange <rory@campbell-lange.net> writes:

> I understand that functions provide an implied transaction in
> PostgreSQL.

Not quite.  Every SQL statement is executed in its own transaction if
BEGIN/END are not explicitly used.  A statment may cause zero, one or
many function calls, but they will all execute in that transaction.

> Does that mean one can ROLLBACK/COMMIT within the body of a
> function?

Not in current versions.

-0Doug

Re: ROLLBACK in a function?

От
Rory Campbell-Lange
Дата:
On 28/05/03, Doug McNaught (doug@mcnaught.org) wrote:
> Rory Campbell-Lange <rory@campbell-lange.net> writes:
>
> > I understand that functions provide an implied transaction in
> > PostgreSQL.
>
> Not quite.  Every SQL statement is executed in its own transaction if
> BEGIN/END are not explicitly used.  A statment may cause zero, one or
> many function calls, but they will all execute in that transaction.
>
> > Does that mean one can ROLLBACK/COMMIT within the body of a
> > function?
>
> Not in current versions.

So in my (eg php) code I should do something like this psuedo code?

BEGIN WORK
    select function ([params])
    if
        result == 0
    then
        rollback
    else
        commit
    end if
END WORK

Rory
--
Rory Campbell-Lange
<rory@campbell-lange.net>
<www.campbell-lange.net>

Re: ROLLBACK in a function?

От
Karsten Hilbert
Дата:
> BEGIN WORK
>     select function ([params])
[...]
> END WORK
No need to rollback/commit if you are dealing with SELECTs
that don't have row modifying side effects.

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

Re: ROLLBACK in a function?

От
Doug McNaught
Дата:
Karsten Hilbert <Karsten.Hilbert@gmx.net> writes:

> > BEGIN WORK
> >     select function ([params])
> [...]
> > END WORK
> No need to rollback/commit if you are dealing with SELECTs
> that don't have row modifying side effects.

Right, but SELECTing a function can do anything.  ;)

-Doug