Re: Nested Transactions in PL/pgSQL

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: Nested Transactions in PL/pgSQL
Дата
Msg-id 20070706000559.GF21455@alvh.no-ip.org
обсуждение исходный текст
Ответ на Re: Nested Transactions in PL/pgSQL  (John DeSoi <desoi@pgedit.com>)
Ответы Re: Nested Transactions in PL/pgSQL  ("Nykolyn, Andrew" <andrew.nykolyn@ngc.com>)
Список pgsql-general
John DeSoi wrote:
>
> On Jul 5, 2007, at 1:34 PM, Nykolyn, Andrew wrote:
>
> >Is it possible to nest transactions within a stored procedure?  I
> >have a stored procedure that calls many other stored procedures and
> >what happens it that after a certain amount of time the server runs
> >out of shared memory.  I know I can increase the PostgreSQL shared
> >memory.  However, that would be a temporary fix.  I know it will
> >eventually run out again as more data is processed.  The right way
> >to do it is to do  issue a save point or commit at various places
> >in my long stored procedure.  I want to believe that there is a way
> >to issue commits within a stored procedure since PostgreSQL now
> >supports nested transactions.
>
> PL/pgSQL functions implicitly run within a transaction, so I don't
> think you can issue BEGIN/COMMIT/ROLLBACK. But save points should be
> OK. Any reason that won't work for your case?

It can't be done directly.  The only way to have a subtransaction in a
PL/pgSQL function is to use an EXCEPTION clause.

You can nest it -- for example have one BEGIN/EXCEPTION/END block inside
another.  You can do it serially as well, along the lines of

BEGIN
    BEGIN
        do stuff
    EXCEPTION WHEN ...
        catch it
    END
    BEGIN
        do more stuff
    EXCEPTION WHEN ...
        same
    END
END

Note that BEGIN here delimits a block; it has no relationship at all
with BEGIN in SQL which starts a transaction.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

В списке pgsql-general по дате отправления:

Предыдущее
От: John DeSoi
Дата:
Сообщение: Re: Nested Transactions in PL/pgSQL
Следующее
От: Chris Travers
Дата:
Сообщение: Localization trouble