Re: sequence, set value of

From: zilch(at)home(dot)se
To: - <pgsql-general(at)postgresql(dot)org>
Subject: Re: sequence, set value of
Date: 2001-06-18 11:28:16
Message-ID: 20010618132816.A17165@loony
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


I have noticed that,
but If I do
select setval('sequence', 1)
the next insert will give me 2.
However the first insert after the creation of the sequence will give me one.

I fixed the problem however.

I create a sequence with minval 0 and do
select setval('sequence', 0)
and it gives me a 1 when I do an insert.

Daniel Akerud

> > 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

Browse pgsql-general by date

  From Date Subject
Next Message zilch 2001-06-18 11:31:01 Re: primary/secondary index, difference
Previous Message Gordan Bobic 2001-06-18 11:27:58 How to disable WAL?