| От | 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 по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера