When I create a new table with a serial column, the first row defaults to
inserting '1'.

If I delete all the rows from the table and want to reset the sequence, I
can't:

ERROR:  users_health_types_type_id_seq.setval: value 0 is out of bounds
(1,9223372036854775807)

How do I set the sequence to have next value = 1?  Surely the bounds should
begin at zero?

Chris


Thu, 13 Mar 2003 11:21:31 +0800
"Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
bug in setval?
Christopher Kings-Lynne wrote:
> How do I set the sequence to have next value = 1?  Surely the bounds should
> begin at zero?
> 

No; see:
http://www.us.postgresql.org/users-lounge/docs/7.3/postgres/functions-sequence.html

Notice the is_called flag. I think this does what you want:
   SELECT setval('foo', 1, false);

Joe


Wed, 12 Mar 2003 19:48:46 -0800
Joe Conway <mail@joeconway.com>
Re: bug in setval?
It's rumoured that Christopher Kings-Lynne once said:
> When I create a new table with a serial column, the first row defaults
> to inserting '1'.
>
> If I delete all the rows from the table and want to reset the sequence,
> I can't:
>
> ERROR:  users_health_types_type_id_seq.setval: value 0 is out of bounds
> (1,9223372036854775807)
>
> How do I set the sequence to have next value = 1?  Surely the bounds
> should begin at zero?

That's bugged me for ages as well. I just never got round to asking about
it...
Regards, Dave.



Thu, 13 Mar 2003 09:48:24 -0000 (GMT)
"Dave Page" <dpage@vale-housing.co.uk>
Re: bug in setval?