Re: sequence, set value of
От | zilch@home.se |
---|---|
Тема | Re: sequence, set value of |
Дата | |
Msg-id | 20010618132816.A17165@loony обсуждение исходный текст |
Ответ на | Re: sequence, set value of (GH <grasshacker@over-yonder.net>) |
Список | 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 >
В списке pgsql-general по дате отправления: