On Mon, 6 May 2013 23:53:40 +0100
Simon Slavin <slav...@bigfraud.org> wrote:

> > How do I create this kind of update statement?
> > 
> > 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.
...
> That was a terrible description. 

Actually that's not a bad approximation of what happens.  Here's a
simpler example:

sqlite> create table t(a int, b int);
sqlite> insert into t values (1,2);
sqlite> select * from t;
a           b         
----------  ----------
1           2         
sqlite> update t set a=b, b=a;  -- Et Voila! 
sqlite> select * from t;
a           b         
----------  ----------
2           1         

There is no "RHS".  The syntax and semantics of SQL are its own; they
cannot be extrapolated from other languages.  

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

Reply via email to