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: 1039247633.1071.5.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
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 http://www.lfix.co.uk/oliver
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

Browse pgsql-novice by date

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