On 14/01/2013 9:48 AM, François-xavier Jacobs wrote:
Hi everyone
i would like to "seed random" a request, so i could do use some pagination
system with a order by random(), is this possible sqlite ? when a tried to
use "order by 1234567892" it always return the same order
That's because you told sqlite that the distinguishing feature of a
tuple is the constant '1234567892' . The sorting routine will see "t1 <
t2 = false" and "t1 > t2 = false" (implying t1 = t2) no matter which two
tuples it examines. If sqlite uses a stable sorting algorithm, that will
leave the input untouched. A very expensive no-op, in other words.
With random(), t1 < t2 is undefined (because it turns out different
every time it's evaluated), and you end up with tuples in a random order
(assuming the sorting routine doesn't crash; code usually assumes values
don't change while being sorted). Note that shuffling directly is more
efficient than "sorting" in this way, though sqlite lacks the necessary
"shuffle" operator to do it in-database.
Ryan
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users