Re: sequence, set value of - Mailing list pgsql-general

From GH
Subject Re: sequence, set value of
Date
Msg-id 20010617192910.A15196@over-yonder.net
Whole thread Raw
In response to Re: sequence, set value of  (zilch@home.se)
Responses Re: sequence, set value of  (zilch@home.se)
List pgsql-general
On Sun, Jun 17, 2001 at 08:51:56PM +0200, some SMTP stream spewed forth:
>
> So, if I want the next insert to make the ID automatically 1, i can't use
> SERIAL since that gives me a sequence of minvalue 1? Wich results in a id =
> 2 in the next insert.
>
> Right?

No. Serial has a minval of 1, correct. However, when the minval is one
and nextval is one, the nextval is...one.
In other words, a newly created serial sequence will return 1 the first
time it is called and 2 the second time. (The case is special when
creating sequences for use
as a serial because you, IIRC, must call nextval() once to make the
nextval one. In other words, the first two values out of a newly created
non-serial sequence with minval=1 are one.)

>
> Daniel Akerud

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Call for alpha testing: planner statistics revisions
Next
From: Randall Perry
Date:
Subject: Re: canned code to get db on web quickly via perl or PHP?