Re: pl/pgSQL & transaction

From: Kovacs Zoltan Sandor <tip(at)pc10(dot)radnoti-szeged(dot)sulinet(dot)hu>
To: Tibor Laszlo <ltibor(at)mail(dot)tiszanet(dot)hu>
Cc: pgsql-interfaces(at)postgresql(dot)org, Zolof <zolof(at)club-internet(dot)fr>
Subject: Re: pl/pgSQL & transaction
Date: 2001-01-20 12:19:24
Message-ID: Pine.LNX.4.05.10101201308160.8598-100000@pc10.radnoti-szeged.sulinet.hu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-general pgsql-interfaces pgsql-sql

On Fri, 19 Jan 2001, Tibor Laszlo wrote:

> > This code doesn't work. I use Begin Work to start a transaction but BEGIN is
> > a PL/pgSQL command so I have a parse error when executing it.
> >
> > CREATE FUNCTION a () RETURNS int4 AS '
> > BEGIN
> > BEGIN WORK;
> > COMMIT WORK;
> > return 1;
> > END;
> > ' LANGUAGE 'plpgsql';
> >
> > What's wrong ????
>
> Is it possible to use transactions in PL/pgSQL functions? AFAIK these functions
No, it is not possible.

> always(?) in a transaction (eg as triggers or as stored pprocs) and PostgreSQL
> doesn't support nested transactions.
Yes, each PL/pgSQL function call must be considered as a transaction (or,
if a transaction is BEGINned before the function call, then the function
is run in the started transaction). Nested transactions are not supported
by PostgreSQL. If an error occurs inside the function, the transaction
will be aborted -- so none of the statements of the function (or, if a
transaction was BEGINned before the function call, then none of the other
statements before the function call inside the transaction) will be
committed to the database (they will be aborted). The only things happen
that the debug, notice and error messages come up.

Zoltan

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Peter Eisentraut 2001-01-21 01:00:17 SQL Guide
Previous Message Bruce Momjian 2001-01-20 00:04:58 Re: Memory leak in lobj example code

Browse pgsql-general by date

  From Date Subject
Next Message Joseph 2001-01-20 13:00:35 Can't set MAX_CONNECTIONS over 32
Previous Message Martijn van Oosterhout 2001-01-20 12:00:30 Re: Re: couple of general questions

Browse pgsql-interfaces by date

  From Date Subject
Next Message Peter Mount 2001-01-20 14:49:07 Re: JDBC gives pq_recvbuf: unexpected EOF on client connection
Previous Message David Wilson 2001-01-20 06:19:46 Compiling latest ODBC Drivers for Windows

Browse pgsql-sql by date

  From Date Subject
Next Message Najm Hashmi 2001-01-20 18:49:04 Correct Syntax for alter table ..add constraint
Previous Message Ian Harding 2001-01-20 05:04:12 Re: pl/pgsql Limits