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

From Kevin Macdonald
Subject BUG #3240: Unexpected evaluation sequence
Date
Msg-id 200704182210.l3IMA3HZ066416@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #3240: Unexpected evaluation sequence
List pgsql-bugs
The following bug has been logged online:

Bug reference:      3240
Logged by:          Kevin Macdonald
Email address:      kevin.macdonald@pentura.ca
PostgreSQL version: 8.2.3
Operating system:   Windows XP
Description:        Unexpected evaluation sequence
Details:

Take these two operations:

SQL> select currval ('seq')

returns 10

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

returns 10, 11

This is ok.

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). It seems that the value
of currval above should have been the value immediately before the SQL
statement was executed -- a value of 11.


Take this example for comparison:

SQL> create table foo (c1 integer, c2 integer)
SQL> insert into foo values (1, 1);
SQL> update foo set c1=c1+1, c2=c1
SQL> select c1, c2 from foo

returns (2, 1)

In this case, although the expression 'c1=c1+1' is executed before the
expression 'c2=c1', the value of 'c1' in the second expression is the value
immediately before the SQL statement was executed.

This behavior contrasts with that from the evaluation of the sequences
above.

Is this inconsistency done on purpose?

Thank you.

pgsql-bugs by date:

Previous
From: ""
Date:
Subject: BUG #3243: foreign key constraint not working?
Next
From: "William Lawrance"
Date:
Subject: BUG #3244: problem with PREPARE