From: | Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: pg_query transaction: auto rollback? begin or start?? commit or end??? |
Date: | 2008-07-23 07:02:35 |
Message-ID: | 20080723070234.GB4168@merkur.hilbert.loc |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Artis Caune | 2008-07-23 07:33:55 | plpgsql functions or queries |
Previous Message | artacus | 2008-07-23 06:01:48 | Re: Substitute a variable in PL/PGSQL. |