setval('myfunsequence', 0) - Mailing list pgsql-general

From Ian Harding
Subject setval('myfunsequence', 0)
Date
Msg-id sdf0544f.093@mail.tpchd.org
Whole thread Raw
Responses Re: setval('myfunsequence', 0)  ("scott.marlowe" <scott.marlowe@ihs.com>)
Re: setval('myfunsequence', 0)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
The subject statement does not work for automagically generated sequences (minvalue is 1 by default, it seems.)  I need
toreset a sequence to where nextval('myfunsequence') is 1, and the only way to do it (I think) is to
setval('myfunsequence',0). 

I can just create this particular sequence with minvalue 0 start 1, but I am wondering what is the downside to this
beingthe default?  Alternatively, is there a way to make setval accept a value that is $start - $increment as seems to
happenon creation? 

Visual Aids Follow...

test=# create sequence myfunsequence;
CREATE
test=# select nextval('myfunsequence');
 nextval
---------
       1
(1 row)

test=# select nextval('myfunsequence');
 nextval
---------
       2
(1 row)

test=# select setval('myfunsequence',0);
ERROR:  myfunsequence.setval: value 0 is out of bounds (1,9223372036854775807)
test=# select setval('myfunsequence',1);
 setval
--------
      1
(1 row)

test=# select nextval('myfunsequence');
 nextval
---------
       2
(1 row)

test=# drop sequence myfunsequence;
DROP
test=# create sequence myfunsequence minvalue 0 start 1;
CREATE
test=# select nextval('myfunsequence');
NOTICE:  myfunsequence.nextval: sequence was re-created
 nextval
---------
       1
(1 row)

test=# select nextval('myfunsequence');
 nextval
---------
       2
(1 row)

test=# select setval('myfunsequence',0);
 setval
--------
      0
(1 row)

test=# select nextval('myfunsequence');
 nextval
---------
       1
(1 row)

Thanks!!

Ian Harding
Programmer/Analyst II
Tacoma-Pierce County Health Department
iharding@tpchd.org
(253) 798-3549


pgsql-general by date:

Previous
From: Matthew Gabeler-Lee
Date:
Subject: Re: Query breaking with unknown expression type (lost s
Next
From: Tom Lane
Date:
Subject: Re: the "/usr/local/pgsql/data" directory size