Skip site navigation (1) Skip section navigation (2)

Re: about select use random

From: wangqi <wangqi(at)edgesoft(dot)cn>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: about select use random
Date: 2012-07-25 05:18:07
Message-ID: 500F818F.1020106@edgesoft.cn (view raw or flat)
Thread:
Lists: pgsql-admin
Hi Tom

If you don't want that, you can use a WITH to lock down the result of a
single random() call.


How should I do it?


于 2012-7-25 10:55, Tom Lane 写道:
> wangqi <wangqi(at)edgesoft(dot)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(at)edgesoft(dot)cn
----------------------------------------------------


In response to

pgsql-admin by date

Next:From: Noe GutierrezDate: 2012-07-25 18:11:05
Subject: Could You help me
Previous:From: wangqiDate: 2012-07-25 03:33:02
Subject: Re: about select use random

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group