Re: Behavior of nextval() and currval()
От | Mike Mascari |
---|---|
Тема | Re: Behavior of nextval() and currval() |
Дата | |
Msg-id | 3BF16958.AD35F546@mascari.com обсуждение исходный текст |
Ответ на | Behavior of nextval() and currval() (Mike Mascari <mascarm@mascari.com>) |
Ответы |
Re: Behavior of nextval() and currval()
|
Список | pgsql-general |
Bruce Momjian wrote: > > So you are asking if the order of column function evaluations is > reliable. I tend to think so. I think the only thing that could > reorder it is rules. and Tom Lane wrote: > > Mike Mascari <mascarm@mascari.com> writes: > > The following works in 7.1. Is this behavior guaranteed or is it the > > subject of possible change in the future? Or am I just "getting > > lucky" that nextval() is evaluated before currval(): > > > SELECT nextval('s'), currval('s'); > > Hmm. SELECT target expressions are indeed evaluated left to right at > present, and I don't see any reason to change that --- but it's not > guaranteed by the spec AFAIK. I think you're right to be wary of > depending on it. Why would you need to do this anyway? It's an odd scenario, where I need to generate primary keys from an INSERT..SELECT and the secondary field should match the primary key in this instance. The secondary field represents a "parent" which refers to itself if the record is not a child (as opposed to say, 0). I've switched to using a CREATE TEMPORARY TABLE AS SELECT.., INSERT..SELECT to avoid the scenario. Thanks, Mike Mascari mascarm@mascari.com > > regards, tom lane
В списке pgsql-general по дате отправления: