Re: problem fetching currval of sequence

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: josh(at)agliodbs(dot)com
Cc: Charles Hauser <chauser(at)duke(dot)edu>, pgsql-sql(at)postgresql(dot)org
Subject: Re: problem fetching currval of sequence
Date: 2002-08-06 20:18:45
Message-ID: 2971.1028665125@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Josh Berkus <josh(at)agliodbs(dot)com> writes:
> No, back in 7.1.0 I was able to call CURRVAL without having previously
> called NEXTVAL, and it would give me the "current" sequence value;
> that is, the same result value as (NEXTVAL() - 1)

I don't believe it, and neither do the 7.1.3 and 7.0.2 databases that
I have handy to check with. For example:

play=> select version();
version
------------------------------------------------------------------
PostgreSQL 7.0.2 on hppa2.0-hp-hpux10.20, compiled by gcc 2.95.2
(1 row)

play=> create sequence seq;
CREATE
play=> select currval('seq');
ERROR: seq.currval is not yet defined in this session
play=> select nextval('seq');
nextval
---------
1
(1 row)

play=> select currval('seq');
currval
---------
1
(1 row)

play=> \c play
You are now connected to database play.
play=> select currval('seq');
ERROR: seq.currval is not yet defined in this session

Are you sure you were not thinking of "select last_value from seq"?
That's about the closest approximation I can think of to a
non-transaction-safe version of currval().

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2002-08-06 20:37:48 Re: problem fetching currval of sequence
Previous Message Josh Berkus 2002-08-06 18:35:20 Re: problem fetching currval of sequence