From: | "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> |
---|---|
To: | Judith <jaltamirano(at)correolux(dot)com(dot)mx> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Sequences problem |
Date: | 2007-08-17 21:50:00 |
Message-ID: | dcc563d10708171450y420e0f8eoca3d2ce9624fc686@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 8/17/07, Judith <jaltamirano(at)correolux(dot)com(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-08-18 05:15:19 | Re: Limited number of polygon function arguments |
Previous Message | Andrew Sullivan | 2007-08-17 21:49:10 | Re: Sequences problem |