From: Scott Marlowe <scott.marlowe@gmail.com>
To: Judith <jaltamirano@correolux.com.mx>
Cc: pgsql-sql@postgresql.org
Subject: Re: Sequences problem
Date: Fri, 17 Aug 2007 16:50:00 -0500
Message-ID: <dcc563d10708171450y420e0f8eoca3d2ce9624fc686@mail.gmail.com> (raw)
In-Reply-To: <46C61410.4070407@correolux.com.mx>
References: <46C61410.4070407@correolux.com.mx>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: scott.marlowe@gmail.com, jaltamirano@correolux.com.mx
Subject: Re: Sequences problem
In-Reply-To: <dcc563d10708171450y420e0f8eoca3d2ce9624fc686@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox