Re: BUG #4684: lastval in function

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #4684: lastval in function
Дата
Msg-id 10880.1235837395@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #4684: lastval in function  ("andreas" <postgresql@elbrief.de>)
Список pgsql-bugs
"andreas" <postgresql@elbrief.de> writes:
> select lastval() ;
>  lastval
> ---------
>        2

> i expected lastval() should be 1, because this is the id from the
> insertstatement.

Well, you can't really rely on that when the statement you're executing
contains two different nextval() calls, as this does.  The order of
evaluation of those calls is unspecified.

Personally I'm of the opinion that anyone who uses lastval() deserves to
lose, precisely because of the risk of this type of interaction.  Use
currval() on one or the other of those sequences, and you'll be at least
a little bit safer.  Even better is to use INSERT RETURNING or some
other alternative so that you can avoid currval() too.

            regards, tom lane

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

Предыдущее
От: "andreas"
Дата:
Сообщение: BUG #4684: lastval in function
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: BUG #4684: lastval in function