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

Re: Test to see if currval will fail?

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Kelly McDonald <w4kpm(at)adelphia(dot)net>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Test to see if currval will fail?
Date: 2002-12-07 07:53:53
Message-ID: (view raw or whole thread)
Lists: pgsql-novice
On Fri, 2002-12-06 at 13:18, Kelly McDonald wrote:
> Josh,
> Actually, I'm not really concerned about what the last value was or is,
> but I am trying to find out if nextval has already been called within
> the current session. so I can do something like:
> if currval_wont_puke('sequence') then
>    select currval('sequence')
> else
>    select nextval('sequence')
> the part that I'm looking for is the currval_wont_puke() function.

Since it is in the _current_ session, surely you can know whether you
have called nextval() without asking the backend?  You need to set a
flag in your program when you use it or do an insert that will trigger
it from a serial column, and test that.

Oliver Elphick                                Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK                   
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
     "Go ye therefore, and teach all nations, baptizing them
      in the name of the Father, and of the Son, and of the 
      Holy Ghost; Teaching them to observe all things  
      whatsoever I have commanded you; and, lo, I am with 
      you alway, even unto the end of the world. Amen."     
            Matthew 28:19,20 

In response to

pgsql-novice by date

Next:From: HarryDate: 2002-12-08 01:10:34
Subject: aggregating into 2 dimensions?
Previous:From: cristiDate: 2002-12-07 06:05:48
Subject: Check sum function

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