pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSequences problem
3+ messages / 3 participants
[nested] [flat]
* Sequences problem
@ 2007-08-17 21:33 Judith <jaltamirano@correolux.com.mx>
2007-08-17 21:49 ` Re: Sequences problem Andrew Sullivan <ajs@crankycanuck.ca>
2007-08-17 21:50 ` Re: Sequences problem Scott Marlowe <scott.marlowe@gmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: Judith @ 2007-08-17 21:33 UTC (permalink / raw)
To: pgsql-sql
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?
Thanks in advanced
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Sequences problem
2007-08-17 21:33 Sequences problem Judith <jaltamirano@correolux.com.mx>
@ 2007-08-17 21:49 ` Andrew Sullivan <ajs@crankycanuck.ca>
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Sullivan @ 2007-08-17 21:49 UTC (permalink / raw)
To: pgsql-sql
On Fri, Aug 17, 2007 at 04:33:04PM -0500, Judith wrote:
> 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)
You _must_ call nextval() before a currval(). This is documented
behaviour.
A
--
Andrew Sullivan | ajs@crankycanuck.ca
The whole tendency of modern prose is away from concreteness.
--George Orwell
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Sequences problem
2007-08-17 21:33 Sequences problem Judith <jaltamirano@correolux.com.mx>
@ 2007-08-17 21:50 ` Scott Marlowe <scott.marlowe@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Scott Marlowe @ 2007-08-17 21:50 UTC (permalink / raw)
To: Judith <jaltamirano@correolux.com.mx>; +Cc: 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.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-08-17 21:50 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-08-17 21:33 Sequences problem Judith <jaltamirano@correolux.com.mx>
2007-08-17 21:49 ` Andrew Sullivan <ajs@crankycanuck.ca>
2007-08-17 21:50 ` Scott Marlowe <scott.marlowe@gmail.com>
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