Re: Transaction Handling in pl/pgsql

From: Douglas McNaught <doug(at)mcnaught(dot)org>
To: "Craig Bryden" <postgresql(at)bryden(dot)co(dot)za>
Cc: "pgsql" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Transaction Handling in pl/pgsql
Date: 2005-07-12 17:43:56
Message-ID: m2ll4bvs0z.fsf@Douglas-McNaughts-Powerbook.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Craig Bryden" <postgresql(at)bryden(dot)co(dot)za> writes:

> 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?

Read up on how in-function exception handling and savepoints interact
for pl/pgsql in 8.0:

http://www.postgresql.org/docs/8.0/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

For previous versions (7.X), the whole thing will be rolled back if
anything in the function throws an exception.

-Doug

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2005-07-12 17:45:37 illegal sort order
Previous Message Jaime Casanova 2005-07-12 17:37:03 Re: Transaction Handling in pl/pgsql