Re: pg_query transaction: auto rollback? begin or start?? commit or end???

Поиск
Список
Период
Сортировка
От Karsten Hilbert
Тема Re: pg_query transaction: auto rollback? begin or start?? commit or end???
Дата
Msg-id 20080723070234.GB4168@merkur.hilbert.loc
обсуждение исходный текст
Ответ на Re: pg_query transaction: auto rollback? begin or start?? commit or end???  (Chris <dmagick@gmail.com>)
Ответы Re: pg_query transaction: auto rollback? begin or start?? commit or end???  ("Bill Wordsworth" <bill.wordsworth@gmail.com>)
Список pgsql-general
On Wed, Jul 23, 2008 at 01:15:30PM +1000, Chris wrote:

> >> Now *any* error inside transaction will trigger auto rollback for
> >> *all* inserts so I don't need to explicitly issue conditional
> >> rollback? Also is "begin/commit transaction" == "start/end
> >> transaction"??
>
> What if something gets an invalid state (eg you expect a record to have
> 'active = 156' but it's something else).
>
> So in some cases yes you'll need to do a rollback. On the other hand, if
> you don't explicitly do a commit, everything is rolled back.
>
> Yes "begin" == "start transaction" and "commit" == "end transaction".

"commit" really is not a well-chosen name for what it is. It
is often clearer to think in terms of the triple

begin

        rollback
end

where begin/end are the standard begin/end transaction
commands while rollback is only ever needed when you detect
a condition someplace logically *outside* the transaction
itself and based on that want to undo the transaction that
is in progress.

Because no matter whether you issue commit or rollback - if
there was an error *inside* the transaction it'll rollback
in any case (unless the error was handled somehow).

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

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

Предыдущее
От: artacus@comcast.net
Дата:
Сообщение: Re: Substitute a variable in PL/PGSQL.
Следующее
От: "Artis Caune"
Дата:
Сообщение: plpgsql functions or queries