Re: Test to see if currval will fail? - Mailing list pgsql-novice

From Kelly McDonald
Subject Re: Test to see if currval will fail?
Date
Msg-id 1039180730.26641.19.camel@shadrach
Whole thread Raw
In response to Re: Test to see if currval will fail?  ("Josh Berkus" <josh@agliodbs.com>)
Responses Re: Test to see if currval will fail?
Re: Test to see if currval will fail?
List pgsql-novice
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.

I have already tried every way that I can think of to catch an exception
by currval, (and learned more since then) and I'm certain that there is
no way to catch an exception, no matter what language you write it in.

I know how to create a function like this, but I'd have to tinker with
backend source (sequence.c) to make it work. - I thought I'd see if
there is an easier way before I go do something crazy like that.

Thanks,
Kelly.



On Thu, 2002-12-05 at 17:56, Josh Berkus wrote:
> Kelly,
> You could do "select last_value from <sequence name>" instead.
>  However, I'm not sure that that method of getting the currval is
> session-protected in the way that currval is.
>
> -Josh Berkus



pgsql-novice by date:

Previous
From: Josh Berkus
Date:
Subject: Re: [GENERAL] Newbee question "Types"
Next
From: Vijay Deval
Date:
Subject: Re: tcl script