Skip site navigation (1) Skip section navigation (2)

Re: Currval function won't work

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: <operationsengineer1(at)yahoo(dot)com>,Bluebottle <luckychap(at)bluebottle(dot)com>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Currval function won't work
Date: 2005-10-07 18:06:40
Message-ID: BF6C3170.10165%sdavis2@mail.nih.gov (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-novice
On 10/7/05 1:26 PM, "operationsengineer1(at)yahoo(dot)com"
<operationsengineer1(at)yahoo(dot)com> wrote:

> 
> 
> --- Bluebottle <luckychap(at)bluebottle(dot)com> wrote:
> 
>> select currval('library.items_itemid_seq') as
>> NextItemID;
>> ERROR:  currval of sequence "items_itemid_seq" is
>> not yet defined in
>> this session
>>  
>> Note that the nextval function works as expected
>>  
>> select nextval('library.items_itemid_seq') as
>> NextItemID;
>> 2313
>>  
>> Can somebody please tell me what simple mistake I am
>> making?
>>  
>> David
> 
> David, I don't know the answer, but this is how i
> would troubleshoot...
> 
> what happens when you try...
> 
> 1. select currval('library.items_itemid_seq');
> 
> 2. select currval('library.items_itemid_seq');
> 
> 3. select currval('library.items_itemid_seq') as
> NextItemID;
> 
> 4. select currval('items_itemid_seq') as NextItemID;
> 
> do any of these work?  do any break?

From the documentation:

http://www.postgresql.org/docs/8.0/interactive/functions-sequence.html

currval

    Return the value most recently obtained by nextval for this sequence in
the current session. (An error is reported if nextval has never been called
for this sequence in this session.) Notice that because this is returning a
session-local value, it gives a predictable answer whether or not other
sessions have executed nextval since the current session did.

Sean


In response to

pgsql-novice by date

Next:From: Andreas KretschmerDate: 2005-10-07 18:09:44
Subject: Re: Intersection of two time segments
Previous:From: Derrick BettsDate: 2005-10-07 17:43:11
Subject: Re: Set Privileges on All Tables (and/or Sequences) at Once

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group