Re: implicit rollback?

From: John DeSoi <desoi(at)pgedit(dot)com>
To: Carol Walter <walterc(at)indiana(dot)edu>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: implicit rollback?
Date: 2009-06-17 18:33:42
Message-ID: B18F37C3-ED1B-4A9D-A3E8-6EA83DE2010A@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


On Jun 17, 2009, at 8:26 AM, Carol Walter wrote:

> I have a program (PHP) that is executing a number of SQL commands as
> a single transaction. At the beginning of the transaction, I have a
> "BEGIN" and at the end I have a "COMMIT". If one of the
> transactions fails, do I have to explicitly issue a "ROLLBACK"
> command, or will postgres do this automatically because one of the
> commands fails?

Postgres does not automatically issue a "ROLLBACK" command. But you
can use "END" instead of "COMMIT". This will commit the transaction if
there are no errors, otherwise it will rollback:

db=# begin;
BEGIN
db=# select 1/0;
ERROR: division by zero
db=# end;
ROLLBACK

Interesting, though, I just noticed that this behavior is not
discussed in the documentation.

http://www.postgresql.org/docs/8.3/interactive/sql-end.html

John DeSoi, Ph.D.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message MITCHELL CIFUENTES 2009-06-17 21:07:54 problem with sequence number using a trigger
Previous Message Mohlomi Moloi 2009-06-17 13:51:14 Re: implicit rollback?