Thread: sequence, set value of

sequence, set value of

From
zilch@home.se
Date:
Forgott how to set the value of a sequence,
please tell.

Daniel Akerud

Re: sequence, set value of

From
Alex Pilosov
Date:
The docs have it.
select setval('foobar_seq',value)


On Sun, 17 Jun 2001 zilch@home.se wrote:

>
> Forgott how to set the value of a sequence,
> please tell.
>
> Daniel Akerud
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
>


Re: sequence, set value of

From
"Tim Barnard"
Date:
select setval('sequencename',newvalue)

See docs at: www.portgresql.org/idocs/index.php?sql-createsequence.html

Tim

----- Original Message -----
From: <zilch@home.se>
To: <pgsql-general@postgresql.org>
Sent: Sunday, June 17, 2001 10:36 AM
Subject: [GENERAL] sequence, set value of


>
> Forgott how to set the value of a sequence,
> please tell.
>
> Daniel Akerud
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


Re: sequence, set value of

From
zilch@home.se
Date:
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?

Daniel Akerud

> select setval('sequencename',newvalue)
>
> See docs at: www.portgresql.org/idocs/index.php?sql-createsequence.html
>
> Tim
>
> ----- Original Message -----
> From: <zilch@home.se>
> To: <pgsql-general@postgresql.org>
> Sent: Sunday, June 17, 2001 10:36 AM
> Subject: [GENERAL] sequence, set value of
>
>
> >
> > Forgott how to set the value of a sequence,
> > please tell.
> >
> > Daniel Akerud
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo@postgresql.org so that your
> > message can get through to the mailing list cleanly
> >
>
>



---
Daniel Åkerud, zilch@home.se








Re: sequence, set value of

From
GH
Date:
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

Re: sequence, set value of

From
zilch@home.se
Date:
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
>