Re: sequence, set value of

From: GH <grasshacker(at)over-yonder(dot)net>
To: zilch(at)home(dot)se
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: sequence, set value of
Date: 2001-06-18 00:29:10
Message-ID: 20010617192910.A15196@over-yonder.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Randall Perry 2001-06-18 02:09:50 Re: canned code to get db on web quickly via perl or PHP?
Previous Message Tom Lane 2001-06-17 20:47:05 Call for alpha testing: planner statistics revisions