resetting serials and sequences

From: Ferruccio Zamuner <nonsolosoft(at)diff(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: resetting serials and sequences
Date: 2001-01-01 15:48:35
Message-ID: 200101011548.f01FmZm13200@tnt.diff.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2001-01-01 19:21:47 Re: Updating two table via a Rule?
Previous Message Michael Davis 2001-01-01 10:41:04 RE: Updating two table via a Rule?