setval('myfunsequence', 0)

From: "Ian Harding" <ianh(at)tpchd(dot)org>
To: <pgsql-general(at)postgresql(dot)org>
Subject: setval('myfunsequence', 0)
Date: 2002-12-06 15:38:36
Message-ID: sdf0544f.093@mail.tpchd.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The subject statement does not work for automagically generated sequences (minvalue is 1 by default, it seems.) I need to reset 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 being the default? Alternatively, is there a way to make setval accept a value that is $start - $increment as seems to happen on 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(at)tpchd(dot)org
(253) 798-3549

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2002-12-06 15:48:45 Re: the "/usr/local/pgsql/data" directory size
Previous Message Matthew Gabeler-Lee 2002-12-06 15:29:45 Re: Query breaking with unknown expression type (lost s