Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux