On 6 May 2013, at 11:53pm, Simon Slavin <slav...@bigfraud.org> wrote:

> On 6 May 2013, at 11:48pm, skywind mailing lists <mailingli...@skywind.eu> 
> wrote:
> 
>> UPDATE T SET a=0.5*(a+b), b=0.5*(b-a);
>> 
>> The RHS should always be used with the values of a and b before the 
>> assignment.
>> 
>> I think that the result of this kind of statement is undefined, or?
> 
> No need to worry, it will work the way you want it to work:
> 
> The row is read.
> The new values are calculated.
> The new values are written to the database.

Okay, could everyone please forget that one ?  That was a terrible description. 
 As far as I know my statement is correct.  The values used in the calculations 
are the values read from the row, not the values SQL is assembling to write 
back to the row.  To make up for my poor explanation please accept this 
demonstration:

sqlite> CREATE TABLE x (a,b);
sqlite> INSERT INTO x VALUES (1,100);
sqlite> SELECT * FROM x;
1|100
sqlite> UPDATE x SET a=b,b=a;
sqlite> SELECT * FROM x;
100|1
sqlite> UPDATE x SET b=a,a=b;
sqlite> SELECT * FROM x;
1|100
sqlite> UPDATE x SET a=999,b=a;
sqlite> SELECT * FROM x;
999|1
sqlite> UPDATE x SET b=a,a=777;
sqlite> SELECT * FROM x;
777|999
sqlite> 

My understanding is that this is part of the SQL standard, though I can't find 
it spelled out anywhere right now.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to