From: | "Bill Wordsworth" <bill(dot)wordsworth(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: pg_query transaction: auto rollback? begin or start?? commit or end??? |
Date: | 2008-07-23 14:44:19 |
Message-ID: | 1e07a2bd0807230744o1b3c8432t773d54e2e135f1aa@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks Chris and Karsten. I still don't quite understand why invalid
state/record-mismatch would also not trigger auto rollback. How can I
even include something *outside* a transaction *inside* it- shouldn't
everything between "begin" and "end" be subject to auto rollback no
matter what?
Also what is the best way to check if transaction is 'read write'
after doing 'pg_query("begin transaction read write;", $connection);'.
pg_transaction_status() doesn't quite do it (read write=?=2).
http://us2.php.net/function.pg_transaction_status
"The status can be PGSQL_TRANSACTION_IDLE (currently idle),
PGSQL_TRANSACTION_ACTIVE (a command is in progress),
PGSQL_TRANSACTION_INTRANS (idle, in a valid transaction block), or
PGSQL_TRANSACTION_INERROR (idle, in a failed transaction block).
PGSQL_TRANSACTION_UNKNOWN is reported if the connection is bad.
PGSQL_TRANSACTION_ACTIVE is reported only when a query has been sent
to the server and not yet completed."
Cheers, Bill
On Wed, Jul 23, 2008 at 3:02 AM, Karsten Hilbert
<Karsten(dot)Hilbert(at)gmx(dot)net> wrote:
> 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
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
From | Date | Subject | |
---|---|---|---|
Next Message | Francisco Reyes | 2008-07-23 15:48:25 | Any way to favor index scans, but not bitmap index scans? |
Previous Message | Scott Marlowe | 2008-07-23 14:43:23 | Re: A couple of newbie questions ... |