Re: problem fetching currval of sequence

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: problem fetching currval of sequence
Дата
Msg-id 2971.1028665125@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: problem fetching currval of sequence  (Josh Berkus <josh@agliodbs.com>)
Ответы Re: problem fetching currval of sequence  (Josh Berkus <josh@agliodbs.com>)
Список pgsql-sql
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


В списке pgsql-sql по дате отправления:

Предыдущее
От: Josh Berkus
Дата:
Сообщение: Re: problem fetching currval of sequence
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: problem fetching currval of sequence