23 апреля 2012 г. 17:53 пользователь Kevin Grittner
<Kevin(dot)Grittner(at)wicourts(dot)gov> написал:
> <suvisor(dot)root(at)gmail(dot)com> wrote:
>
>> select * from testt where id = (random()* 100000)::integer;
>>
>> And sometimes it comes out something like this:
>> id | val
>> -------+--------
>> 11894 | 15051
>> 29233 | 42198
>> 80725 | 90213
>> 85688 | 100992
>> 88017 | 108075
>> (5 rows)
>> Here can be 2, 3 or other rows amount in result... But must be
>> only one!
>
> No, what you have written will scan the entire table and give each
> row a 1 in 100000 chance of being selected. Maybe something like
> this would give you what you want:
>
Hmm, is this because random() marked as volatile (and would be called
for every row)? Ups, I not taken this into account... Sorry for bothering
and thanks for reply!