Re: [sqlite] problem using random() in queries

2008-08-30 Thread Wiktor Adamski
> Richard, Before you "fix" it, I'm not convinced it is broken. > > >From MS SQL server > > create table _names (N varchar(5)); > insert into _names values('a'); > insert into _names values('b'); > insert into _names values('c'); > insert into _names values('d'); > insert into _names values('e');

Re: [sqlite] problem using random() in queries

2008-08-29 Thread cmartin
mySQL differs from MS SQL in it random function handling: SELECT i, RAND() AS R1, RAND() AS R2 FROM z where RAND() < .4; iR1R2 1 0.531666 0.692986 3 0.743755 0.906643 4 0.789811 0.04321 6 0.977431 0.576784 8 0.284047 0.336876 Different values for R1 and R2 (each call

Re: [sqlite] problem using random() in queries

2008-08-29 Thread Noah Hart
, August 29, 2008 9:39 AM To: sqlite-users@sqlite.org Subject: Re: [sqlite] problem using random() in queries Noah Hart <[EMAIL PROTECTED]> wrote: > I would expect that multiple calls to random always return different > values, even if in the same line. > > The fact that we are ali

Re: [sqlite] problem using random() in queries

2008-08-29 Thread Igor Tandetnik
Noah Hart <[EMAIL PROTECTED]> wrote: > I would expect that multiple calls to random always return different > values, even if in the same line. > > The fact that we are aliasing random by a column name makes no > difference to me. What about this: select name, RNDValue from ( select name, ran

Re: [sqlite] problem using random() in queries

2008-08-29 Thread Noah Hart
Richard, Before you "fix" it, I'm not convinced it is broken. >From MS SQL server create table _names (N varchar(5)); insert into _names values('a'); insert into _names values('b'); insert into _names values('c'); insert into _names values('d'); insert into _names values('e'); select N, RAND()

Re: [sqlite] problem using random() in queries

2008-08-28 Thread D. Richard Hipp
On Aug 28, 2008, at 12:00 PM, Igor Tandetnik wrote: > Tmb <[EMAIL PROTECTED]> wrote: >> I created a SQLite database where a table 'names' is located. This >> table stores just a single column called 'name'. Now I tried for test >> purposes to create a random number within range [0..1] for each >>

Re: [sqlite] problem using random() in queries

2008-08-28 Thread Dennis Cote
Igor Tandetnik wrote: > > It looks like random() is run twice for each row - once in WHERE clause > and again in the SELECT clause. This looks like a bug. > I agree, this looks like a bug. This is a simpler query that shows the same problem. sqlite> create table t (id, a); sqlite> select a, r

Re: [sqlite] problem using random() in queries

2008-08-28 Thread Dennis Cote
Tmb wrote: > I created a SQLite database where a table 'names' is located. This table > stores just a single column called 'name'. Now I tried for test purposes to > create a random number within range [0..1] for each record in the table > using a SELECT statement like this: > > select name, (rand

Re: [sqlite] problem using random() in queries

2008-08-28 Thread Igor Tandetnik
Tmb <[EMAIL PROTECTED]> wrote: > Igor Tandetnik wrote: >> >> Try this: >> >> select name, RNDValue >> from ( >> select name, (random() / 9223372036854775807.0 + 1.0) / 2.0 as >> RNDValue from names >> ) >> where RNDValue >= 0.99; >> > > Thank you for your answer. I tried the subselect and it se

Re: [sqlite] problem using random() in queries

2008-08-28 Thread Tmb
Igor Tandetnik wrote: > > Try this: > > select name, RNDValue > from ( > select name, (random() / 9223372036854775807.0 + 1.0) / 2.0 as > RNDValue from names > ) > where RNDValue >= 0.99; > > Igor Tandetnik > > Thank you for your answer. I tried the subselect and it seems that there

Re: [sqlite] problem using random() in queries

2008-08-28 Thread Igor Tandetnik
Tmb <[EMAIL PROTECTED]> wrote: > I created a SQLite database where a table 'names' is located. This > table stores just a single column called 'name'. Now I tried for test > purposes to create a random number within range [0..1] for each > record in the table using a SELECT statement like this: > >

[sqlite] problem using random() in queries

2008-08-28 Thread Tmb
I created a SQLite database where a table 'names' is located. This table stores just a single column called 'name'. Now I tried for test purposes to create a random number within range [0..1] for each record in the table using a SELECT statement like this: select name, (random() / 922337203685477