[HACKERS] Explicit subtransactions for PL/Tcl

Поиск
Список
Период
Сортировка
От Victor Wagner
Тема [HACKERS] Explicit subtransactions for PL/Tcl
Дата
Msg-id 20170108205750.2dab04a1@wagner.wagner.home
обсуждение исходный текст
Ответы Re: [HACKERS] Explicit subtransactions for PL/Tcl  (Victor Wagner <vitus@wagner.pp.ru>)
Re: [HACKERS] Explicit subtransactions for PL/Tcl  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-hackers
Collegues!

Recently I've found out that PL/Python have very nice feature - explicit
subtransaction object, which allows to execute block of code in the
context of subtransaction.

I've quite surprised that other PL languages, shipped with PostgreSQL do
not have such useful construction. 

If it might require considerable trickery to add such functionality into
PL/Perl, Tcl allows to add new control stuctures very easily.

I'm attaching the patch which implements subtransaction command for
PL/Tcl which does almost same as PL/Python plpy.subtransction context
manager object does: executes a block of Tcl code in the context of
subtransaction, rolls subtransaction back if error occures and commits
it otherwise.

It looks like

subtransaction {
     ...some Tcl code...
}

Typically one would use it inside Tcl catch statement:

if [catch {
    subtransaction {
        spi_exec "insert into..."
                ...
    }
} errormsg] {
   # Handle an error
}

See documentation and tests included in the patch for more complete
examples.

Just like corresponding Python construction, this command doesn't
replace language  builtin exception handling, just adds subtransaction 
support to it.

Patch includes sufficiently less tests than python subtransaction tests,
because Tcl implementation is way simpler than python one, and doesn't
have syntactic variatons which depend on language version.

Also entering and exiting subtransactions are in the same piece of code
rather than in separate __enter__ and __exit__ methods as in Python, so
there is no possibility to call exit without enter or vice versa.

-- 
                                   Victor Wagner <vitus@wagner.pp.ru>

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

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

Предыдущее
От: Greg Stark
Дата:
Сообщение: Re: [HACKERS] [PATCH] guc-ify the formerly hard-coded MAX_SEND_SIZE to max_wal_send
Следующее
От: Victor Wagner
Дата:
Сообщение: Re: [HACKERS] Explicit subtransactions for PL/Tcl