Re: pgsql & transaction doubt

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: pgsql & transaction doubt
Date: 2007-01-26 07:48:53
Message-ID: 20070126074853.GB15591@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

am Fri, dem 26.01.2007, um 8:39:16 +0100 mailte Luca Ferrari folgendes:
> Hi all,
> a little doubt that came into my mind reading the official manual (chapter 37,
> page 677): "functions and trigger procedures are always executed within a
> transaction established by an outer query". What does "outer" means? If I'd
> like a function to be execute within a transaction should I manually begin
> and end the transaction or is the procedure code always executed in a kind of
> subtransaction? I mean, supposing a function raises an exception, what
> happens to all the sql statement issued by the function before the exception?
> Are they automatically rollbacked?

If you call a function "select my_function(param1, param2);", then is
this select the 'outer' query and starts a transaction. An exception
within the function rollback the whole function.

If you have a code like this:

begin;
insert into foo ...
select my_function(param1, param2);
commit;

and the function fails, then fails also the insert before your function.

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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Oisin Glynn 2007-01-26 23:25:06 Re: [NOVICE] Windows 2K Installation difficulties...
Previous Message Luca Ferrari 2007-01-26 07:39:16 pgsql & transaction doubt