pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: wangqi <wangqi@edgesoft.cn>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-admin@postgresql.org
Subject: Re: about select use random
Date: Wed, 25 Jul 2012 13:18:07 +0800
Message-ID: <500F818F.1020106@edgesoft.cn> (raw)
In-Reply-To: <12603.1343184929@sss.pgh.pa.us>
References: <500F5870.8010400@edgesoft.cn>
	<12603.1343184929@sss.pgh.pa.us>

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@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
----------------------------------------------------




view thread (4+ messages)

Message-ID: <500F818F.1020106@edgesoft.cn>
Permalink:  ../500F818F.1020106@edgesoft.cn/
Also on:    postgresql.org/message-id/500F818F.1020106@edgesoft.cn

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: wangqi@edgesoft.cn, tgl@sss.pgh.pa.us
  Subject: Re: about select use random
  In-Reply-To: <500F818F.1020106@edgesoft.cn>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox