Re: Questions about rollback and commit - Mailing list pgsql-general

From Nils Zonneveld
Subject Re: Questions about rollback and commit
Date
Msg-id 3B52D778.14DDFB04@mbit.nl
Whole thread Raw
In response to Questions about rollback and commit  (Fariba Noorbakhsh <fNoorbakhsh@tecways.com>)
List pgsql-general

Fariba Noorbakhsh wrote:
>
> Hello,
>
> I tried Rollback after update or insert, but it doesn't work!
> How can I rollback the update, insert or delete  changes I have made in
> pgsql?
> Do I need to do commit after each update or insert?
> Do update, insert or delete consider as transactions?
>

Every update and insert is wrapped in an implicit transaction. You can
however use transactions explicitly with 'begin;', you can then do
whatever sequence of updates and inserts until you give the 'commit;' or
'rollback;' command. When a SQL statement returns an error a rollback
will be issued by PostgreSQL and you would have to do the sequence
again. Next some examples from a psql session:

test=# insert into bar (foo) values ('foobar');
INSERT 15386527 1
test=# select * from bar;
  foo
--------
 foobar
(1 row)

test=# begin;
BEGIN
test=# insert into bar (foo) values ('barfoo');
INSERT 15386528 1
test=# select * from bar;
  foo
--------
 foobar
 barfoo
(2 rows)

test=# rollback;
ROLLBACK
test=# select * from bar;
  foo
--------
 foobar
(1 row)

test=#

test=# begin;
BEGIN
test=# insert into bar (foo) values ('barfoo');
INSERT 15386529 1
test=# commit;
COMMIT
test=# select * from bar;
  foo
--------
 foobar
 barfoo
(2 rows)

test=#



Regards,

Nils
--
Alles van waarde is weerloos
Lucebert

pgsql-general by date:

Previous
From: "Michael Beckstette"
Date:
Subject: how to obtain informations about current connections
Next
From: "Przemyslaw 'Morp][ik' Berlinski"
Date:
Subject: Copy and serial type problem