Can't setval() a sequence to return the first value

Started by Hannu Krosingover 13 years ago2 messageshackers
Jump to latest
#1Hannu Krosing
hannu@tm.ee

Hi hackers.

Is it by design that you can't setval(seq, value) a sequence to a value
which returns the first value:

See the sample below for better explanation:

hannu=# create sequence s;
CREATE SEQUENCE
hannu=# select nextval('s');
nextval
---------
1
(1 row)
hannu=# select setval('s',1);
setval
--------
1
(1 row)
hannu=# select nextval('s');
nextval
---------
2
(1 row)
hannu=# select setval('s',0);
ERROR: setval: value 0 is out of bounds for sequence "s"
(1..9223372036854775807)

Should it not be possible to set sequence to one below the start value
so that you can completely reset it ?

--------------------
Hannu

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Hannu Krosing (#1)
Re: Can't setval() a sequence to return the first value

Hello

postgres=# select setval('xx', 1, false);
setval
--------
1
(1 row)

postgres=# select nextval('xx');
nextval
---------
1
(1 row)

Regards

Pavel

2013/1/3 Hannu Krosing <hannu@2ndquadrant.com>:

Hi hackers.

Is it by design that you can't setval(seq, value) a sequence to a value
which returns the first value:

See the sample below for better explanation:

hannu=# create sequence s;
CREATE SEQUENCE
hannu=# select nextval('s');
nextval
---------
1
(1 row)
hannu=# select setval('s',1);
setval
--------
1
(1 row)
hannu=# select nextval('s');
nextval
---------
2
(1 row)
hannu=# select setval('s',0);
ERROR: setval: value 0 is out of bounds for sequence "s"
(1..9223372036854775807)

Should it not be possible to set sequence to one below the start value so
that you can completely reset it ?

--------------------
Hannu

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers