Thread: sequence rollback?

sequence rollback?

From
stig erikson
Date:
hello.
is it possible to rollback sequences in postgresql 8.1.1?
(tested om FC4 with official rpms).

it seems like a sequence is always moving forward and cannot be rolled
back. is this correct?
if it is correct, where in the docs do i find information about this
behavior?

/stig



testcase:

bash-2.05b$ createdb testseq
CREATE DATABASE

bash-2.05b$ psql -d testseq
Welcome to psql 8.1.1, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
        \h for help with SQL commands
        \? for help with psql commands
        \g or terminate with semicolon to execute query
        \q to quit

testseq=# create sequence test_seq increment 1 minvalue 1;
CREATE SEQUENCE
testseq=# create table test0 ( id int8 NOT NULL DEFAULT
nextval('test_seq'), text varchar(20) );
CREATE TABLE
testseq=# begin;
BEGIN
testseq=# insert into test0 (text) values('hello');
INSERT 0 1
testseq=# select * from test0;
  id | text
----+-------
   1 | hello
(1 row)

testseq=# rollback;
ROLLBACK
testseq=# begin;
BEGIN
testseq=# insert into test0 (text) values('hello');
INSERT 0 1
testseq=# select * from test0;
  id | text
----+-------
   2 | hello
(1 row)

testseq=# rollback;
ROLLBACK

Re: sequence rollback?

From
Michael Fuhr
Date:
On Sun, Dec 18, 2005 at 02:02:49PM +0100, stig erikson wrote:
> it seems like a sequence is always moving forward and cannot be rolled
> back. is this correct?

Yes.

> if it is correct, where in the docs do i find information about this
> behavior?

http://www.postgresql.org/docs/faqs.FAQ.html#item4.11.4
http://www.postgresql.org/docs/8.1/interactive/functions-sequence.html

--
Michael Fuhr