Re: Test to see if currval will fail?

From: Kelly McDonald <w4kpm(at)adelphia(dot)net>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Test to see if currval will fail?
Date: 2002-12-06 13:18:49
Message-ID: 1039180730.26641.19.camel@shadrach
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Vijay Deval 2002-12-06 15:44:54 Re: tcl script
Previous Message Joel Burton 2002-12-06 03:01:11 Re: Newbee question "Types"