Re: BUG #3240: Unexpected evaluation sequence - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #3240: Unexpected evaluation sequence
Date
Msg-id 16887.1177045137@sss.pgh.pa.us
Whole thread Raw
In response to BUG #3240: Unexpected evaluation sequence  ("Kevin Macdonald" <kevin.macdonald@pentura.ca>)
List pgsql-bugs
"Kevin Macdonald" <kevin.macdonald@pentura.ca> writes:
> Now, take these two operations:

> SQL> select currval ('seq')

> returns 11

> SQL> select nextval ('seq'), currval ('seq')

> returns (12, 12)

> I would have expected it to have returned (12, 11).

No, because currval reports the latest nextval result in your session,
and the nextval has already been executed.  This is dependent on order
of execution of select-list items, but at the moment that's always
left-to-right.

> It seems that the value
> of currval above should have been the value immediately before the SQL
> statement was executed -- a value of 11.

Since sequence operations are non-transactional by definition, I'm not
really sure why you'd expect that.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #3245: PANIC: failed to re-find shared lock object
Next
From: Tom Lane
Date:
Subject: Re: BUG #3243: foreign key constraint not working?