I have a text column containing floating point strings like 23.6, 8.4, 0.3, 
etc. These always have just the one digit after the decimal point. This column 
was sometimes being used in an ORDER BY and then I realised that it wasn't 
going to sort properly. The use of a TEXT field was deliberate in that it 
speeded up other things for the user, and the column in question was relatively 
unlikely to be used very often in the ORDER BY.

To fix the sort, I resorted to this:

  ... ORDER BY ROUND (myfield, 1);

but now I see I could just as well do:

  ... ORDER BY CAST (myfield AS REAL);

and a small test appears to confirm that this produces the same results.

Is the CAST likely to be significantly faster that the ROUND, if the table is 
limited to say 20k rows? I prefer the CAST as it states more clearly what I'm 
trying to do - always to be preferred in software IMO.



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

Reply via email to