Re: Sequences problem

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: Sequences problem
Дата
Msg-id dcc563d10708171450y420e0f8eoca3d2ce9624fc686@mail.gmail.com
обсуждение исходный текст
Ответ на Sequences problem  (Judith <jaltamirano@correolux.com.mx>)
Список pgsql-sql
On 8/17/07, Judith <jaltamirano@correolux.com.mx> wrote:
> Hello everybody, I have a question related with sequences.............
>
> When I init a sesion with my db, if a do the next sentence:
>
>     SELECT   currval('pagos_id_pago_seq');
>
>
> return this:
>    ERROR: the relation doesn't exist
>     (or somethimg like that, because the message is in spanish)
>
> but if I do first,
>
>     SELECT nextval('pagos_id_pago_seq');
>
> and then
>     SELECT currval('pagos_id_pago_seq');   it success, returns the
> current sequence value,  it is possible to indicate that the sequence is
> already started and in the value 4567 but I need first to now the
> current value before the next, how can I do?

Sorry, that's not how sequences work.

Have you read the manual on sequence manipulation?

http://www.postgresql.org/docs/8.2/static/functions-sequence.html

Sequences are designed to allow fast access to sequentially increasing
numbers to use as identifiers in the database.  While they guarantee
no repeats (unless you set them to roll over etc...) they don't
guarantee no gaps.

so, the current value only has context if you've actually pulled a
sequence from the generator, otherwise what it is right now isn't
really important yet.

There are some functions you can use to get the current number, but
doing that is not safe from race conditions, so you should only do
that stuff while access to the db is shut off to other users.


В списке pgsql-sql по дате отправления:

Предыдущее
От: Andrew Sullivan
Дата:
Сообщение: Re: Sequences problem
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Limited number of polygon function arguments