Re: Transaction Handling in pl/pgsql

From: "Craig Bryden" <postgresql(at)bryden(dot)co(dot)za>
To: "Jaime Casanova" <systemguards(at)gmail(dot)com>
Cc: "pgsql" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Transaction Handling in pl/pgsql
Date: 2005-07-12 18:44:40
Message-ID: 001701c58711$c3e73330$0200a8c0@amd2800
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

What if the select calling my function is not in it's own explicit
transaction block?

Thanks
Craig

----- Original Message -----
From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
To: "Craig Bryden" <postgresql(at)bryden(dot)co(dot)za>
Cc: "pgsql" <pgsql-general(at)postgresql(dot)org>
Sent: Tuesday, July 12, 2005 7:37 PM
Subject: Re: [GENERAL] Transaction Handling in pl/pgsql

On 7/12/05, Craig Bryden <postgresql(at)bryden(dot)co(dot)za> wrote:
> Hi
>
> I am trying to get a better understanding of how transactions work in
> pl/pgsql functions. I found the following text in the help:
> "It is important not to confuse the use of BEGIN/END for grouping
statements
> in PL/pgSQL with the database commands for transaction control. PL/pgSQL's
> BEGIN/END are only for grouping; they do not start or end a transaction"
> but I am still a bit confused.
>
> Suppose I have a function that will be called from an application. Will
all
> the statements in the function be rolled back if the last one generates an
> exception? or do I need to add code to a function to make that happen?
>
>

suppose you have: select your_function();

your_function adds some rows but the last one gives an error, because
all statements that are out of a transaction block are in its own
transaction the select calling your_function is inside a
transaction... so, the answer is yes... the statements inside the
function will be rolled back

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Douglas McNaught 2005-07-12 18:46:18 Re: Transaction Handling in pl/pgsql
Previous Message Tom Lane 2005-07-12 18:44:25 Re: Japanese words not distinguished