what happens if something goes wrong in transaction?

Started by A Babout 18 years ago3 messagesgeneral
Jump to latest
#1A B
gentosaker@gmail.com

Hi. newbie question, but what will happen if I do

begin work;
select ...
insert ...
and so on...
commit

and somewhere a query fails. will I get an automatic rollback? If not, is
there a way to get that behaviour?
I'm using php to make all these calls and they have all to be succesfull or
no one of them should be carried out.

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: A B (#1)
Re: what happens if something goes wrong in transaction?

A B escribi�:

Hi. newbie question, but what will happen if I do

begin work;
select ...
insert ...
and so on...
commit

and somewhere a query fails. will I get an automatic rollback?

Of course.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#3Michael Fuhr
mike@fuhr.org
In reply to: A B (#1)
Re: what happens if something goes wrong in transaction?

On Thu, Feb 28, 2008 at 02:19:01PM +0000, A B wrote:

Hi. newbie question, but what will happen if I do

begin work;
select ...
insert ...
and so on...
commit

and somewhere a query fails. will I get an automatic rollback?

After the error every subsequent statement will fail with "ERROR:
current transaction is aborted, commands ignored until end of
transaction block." The transaction doesn't automatically end but
it will roll back even if you try to commit (assuming you didn't
do a partial rollback with SAVEPOINT/ROLLBACK TO).

I'm using php to make all these calls and they have all to be succesfull or
no one of them should be carried out.

That's the behavior you'll get if you use a transaction. No changes
will be visible to other transactions until you successfully commit.

--
Michael Fuhr