Josh Berkus <josh@agliodbs.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
gcc2.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