From: | Nils Zonneveld <nils(at)mbit(dot)nl> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Questions about rollback and commit |
Date: | 2001-07-16 12:01:02 |
Message-ID: | 3B52D778.14DDFB04@mbit.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Huxton | 2001-07-16 12:23:50 | Re: Questions about rollback and commit |
Previous Message | Paulo Jan | 2001-07-16 11:48:18 | Upgrading binary RPMs |