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

From Adam Haberlach
Subject Current value of a sequence?
Date
Msg-id 20010603123422.A29898@newsnipple.com
Whole thread Raw
Responses Re: Current value of a sequence?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Current value of a sequence?  (will trillich <will@serensoft.com>)
List pgsql-general
I'm trying to find the next value that will be assigned by a sequence
without actually incrementing it (yes, I know it isn't atomic-safe
and all)

I had a lot of trouble finding information about sequences in
the current documentation (maybe it is in the A4 PDF version or
something).  When I finally resorted to trolling through the
source code, and found currval, it seems to have an odd (IMHO)
behavior:

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?)


--
Adam Haberlach            | At either end of the social spectrum there lies
adam@newsnipple.com       | a leisure class.  -- Eric Beck 1965
http://www.newsnipple.com |
'88 EX500    '00 >^<      | http://youlook.org

pgsql-general by date:

Previous
From: teg@redhat.com (Trond Eivind Glomsrød)
Date:
Subject: Re: 7.1.2 packaging
Next
From: Francesco Casadei
Date:
Subject: return value of a version-1 C function