Home > Archive > PostgreSQL SQL > December 2006 > transaction in function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author transaction in function
Marian POPESCU

2006-12-05, 7:18 pm

Hi,

I want to write a function that updates several tables; if there is an
exception while updating, it should rollback the transaction and raise an
error.

How can this be done in pgPLSQL in PostgreSQL 8.1 ?

Thank you for helping me out on this one !



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

A. Kretschmer

2006-12-05, 7:18 pm

am Tue, dem 05.12.2006, um 16:25:31 +0100 mailte Marian POPESCU folgendes:
> Hi,
>
> I want to write a function that updates several tables; if there is an
> exception while updating, it should rollback the transaction and raise an
> error.
>
> How can this be done in pgPLSQL in PostgreSQL 8.1 ?


A function runs within a transaction. You can trapp errors within a
function, read this:

http://www.postgresql.org/docs/8.1/...-ERROR-TRAPPING


Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Tom Lane

2006-12-05, 7:18 pm

Marian POPESCU < softexpert@libertysu
rf.fr> writes:
> I want to write a function that updates several tables; if there is an
> exception while updating, it should rollback the transaction and raise an
> error.


> How can this be done in pgPLSQL in PostgreSQL 8.1 ?


You just do it. You would have to work at it to *not* have that behavior.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Din Adrian

2006-12-05, 7:18 pm

Any function runs into a single transaction so you don't need to worry
about rolling back on exceptions - this is the standard behavior. If there
is an exception while running any statement inside the function it's
rolls back automatically.


On Tue, 05 Dec 2006 17:25:31 +0200, Marian POPESCU
< softexpert@libertysu
rf.fr> wrote:

> Hi,
>
> I want to write a function that updates several tables; if there is an
> exception while updating, it should rollback the transaction and raise an
> error.
>
> How can this be done in pgPLSQL in PostgreSQL 8.1 ?
>
> Thank you for helping me out on this one !
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com