Обсуждение: resetting serials and sequences

Поиск
Список
Период
Сортировка

resetting serials and sequences

От
Ferruccio Zamuner
Дата:
Hi,

#create temp table a (      id serial primary key,      name text not null);

#insert into a (name) values ('Tom');
#insert into a (name) values ('Fer');
#insert into a (name) values ('Mario');

#select * from a;id | name  
----+------- 1 | Tom 2 | Fer 3 | Mario
(3 rows)

OK. Now for some reason I need to reset everything without drop tables:

#delete from a;
#select setval ('a_id_seq', 1);
vacuum;

And now reinsert items:
#insert into a (name) values ('Tom');
#insert into a (name) values ('Fer');
#insert into a (name) values ('Mario');

#select * from a;id | name  
----+------- 2 | Tom 3 | Fer 4 | Mario
(3 rows)

We have missed the id "1"!!!

Otherway:
#select setval('a_id_seq', 0);
ERROR:  a_id_seq.setval: value 0 is of of bounds (1,2147483647)


Is this a bug?         


Best wishes for the brand new year           \fer


Re: resetting serials and sequences

От
Tom Lane
Дата:
Ferruccio Zamuner <nonsolosoft@diff.org> writes:
> Is this a bug?         

No, but it is a missing feature: there's no way to reset a sequence's
is_called flag once it's been set.  This is fixed for 7.1: there's now
a three-parameter variant of setval() to let you do exactly that.
        regards, tom lane