Re: Current value of a sequence? - Mailing list pgsql-general

From missive@frontiernet.net (Lee Harr)
Subject Re: Current value of a sequence?
Date
Msg-id 9femth$t8i$1@node21.cwnet.roc.gblx.net
Whole thread Raw
In response to Current value of a sequence?  (Adam Haberlach <adam@newsnipple.com>)
List pgsql-general
On Sun, 3 Jun 2001 19:48:42 +0000 (UTC), Adam Haberlach <adam@newsnipple.com>:

> zipcode=# select currval('messages_pkey_seq');
> ERROR:  messages_pkey_seq.currval is not yet defined in this session
>
> ...however, if I select nextval() first, it works.  Is this
> lazy caching?  Is there a good way to find the current value of
> sequence without querying directly (and possibly breaking in
> future implementations?)


This is the way sequences are supposed to work.
currval is the current value of the sequence as seen
by the current session. That's why it is not defined
until you select nextval first.

Remember that a sequence is not guaranteed to not
have spaces...

If you want to find the last number from the sequence
which was inserted in to a table, you should select max()
on that column.


pgsql-general by date:

Previous
From: "Sergey E. Volkov"
Date:
Subject: Re: Pgsql vs Interbase: Transaction benchmark
Next
From: "Frank"
Date:
Subject: about PostgreSQL...(important)