Hi All,

Hmm.... Probably need to join the email list.
Did a bit more research into this  - if you place random() in a seperate
view yo can control the behaviour a little better..

Given

CREATE VIEW randomise as select abs(random()) as r;

With the original query, as before random is called more than once.

sqlite> select l2, substr(l2,1,1), substr(l2,2,1)
   ...> FROM
   ...> (select substr(a,((abs(random()) % 13)*2)+1,2) AS l2
   ...> FROM
   ...> (select 'abcdefghijklmnopqrstuvwxyz' as a) alpha) l2;
l2    substr(l2,1,1  subs
----  -------------  ----
uv    a              p
sqlite>

if I use the view to generate the random number then it is only called once.
sqlite> select l2, substr(l2,1,1), substr(l2,2,1)
   ...> FROM
   ...> (select substr(a,((r % 13)*2)+1,2) AS l2
   ...> FROM
   ...> (select 'abcdefghijklmnopqrstuvwxyz' as a) alpha, randomise r) l2;
l2    substr(l2,1,1  subs
----  -------------  ----
qr    q              r

Least I can do what I want now, just need to bring the randomise view into
the query each time for each random number I want.

Simon
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to