Re: Current value of a sequence?

From: missive(at)frontiernet(dot)net (Lee Harr)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Current value of a sequence?
Date: 2001-06-04 01:05:53
Message-ID: 9femth$t8i$1@node21.cwnet.roc.gblx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 3 Jun 2001 19:48:42 +0000 (UTC), Adam Haberlach <adam(at)newsnipple(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Gould 2001-06-04 01:20:40 editing postgresql.conf for network access
Previous Message pgsql-general 2001-06-04 00:43:16 PostgreSQL: Elephant book TOC