Re: about select use random - Mailing list pgsql-admin

From wangqi
Subject Re: about select use random
Date
Msg-id 500F68EE.5000602@edgesoft.cn
Whole thread Raw
In response to Re: about select use random  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-admin
Thanks Tom, I try it.


于 2012-7-25 10:55, Tom Lane 写道:
> wangqi <wangqi@edgesoft.cn> writes:
>> ■SQL-3
>> select * from wk_mclid1 where id1= (round((random() * (10-1))::integer)
>> + 1)::integer;
>> When we excute SQL-3,sometimes the result was 0 record or more than 1
>> record.
>> Why?
> random() is re-evaluated for each row scanned by the SELECT.
>
> If you don't want that, you can use a WITH to lock down the result of a
> single random() call.
>
>             regards, tom lane
>


--
----------------------------------------------------
Yours sincerely,
Qi Wang
                         Edgesoft (China) Co.,Ltd
                         F26th Block B,Zhongli Building,
                         No.32 Huoju Road,
                         Hi-Tech Zone,Dalian,China
                         Zip:116023
                         Tel:+86-411-84753511
                         Fax:+86-411-84753577
                         http://www.edgesoft.cn
                         mailto:wangqi@edgesoft.cn
----------------------------------------------------


pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: about select use random
Next
From: wangqi
Date:
Subject: Re: about select use random