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

From: Chris <dmagick(at)gmail(dot)com>
To: Bill Wordsworth <bill(dot)wordsworth(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: pg_query transaction: auto rollback? begin or start?? commit or end???
Date: 2008-07-23 03:15:30
Message-ID: 4886A252.8030805@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bill Wordsworth wrote:
> ...resending, email didn't go through.
>
> On Tue, Jul 22, 2008 at 1:02 PM, Bill Wordsworth
> <bill(dot)wordsworth(at)gmail(dot)com> wrote:
>> Is this recommended?
>>
>> pg_query("begin transaction read write;", $connection);
>> if(pg_transaction_status($connection) == 2) {
>> pg_query("insert...;", $connection);
>> pg_query("insert...;", $connection);
>> pg_query("insert...;", $connection);
>> }
>> pg_query("commit transaction;", $connection);
>> pg_close($connection);
>>
>> 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".

--
Postgresql & php tutorials
http://www.designmagick.com/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message artacus 2008-07-23 06:01:48 Re: Substitute a variable in PL/PGSQL.
Previous Message Steve Martin 2008-07-23 03:07:39 Re: Substitute a variable in PL/PGSQL.