BUG #3240: Unexpected evaluation sequence

From: "Kevin Macdonald" <kevin(dot)macdonald(at)pentura(dot)ca>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3240: Unexpected evaluation sequence
Date: 2007-04-18 22:10:03
Message-ID: 200704182210.l3IMA3HZ066416@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 3240
Logged by: Kevin Macdonald
Email address: kevin(dot)macdonald(at)pentura(dot)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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Magnus Hagander 2007-04-19 07:21:05 Re: BUG #3232: Regression: pgsql server startup problem with encrypted partitions
Previous Message Bruce Momjian 2007-04-18 21:23:00 Re: BUG #3237: function to_char() returns wrong value