pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: wangqi <wangqi@edgesoft.cn>
To: pgsql-admin@postgresql.org
Subject: about select use random
Date: Wed, 25 Jul 2012 10:22:40 +0800
Message-ID: <500F5870.8010400@edgesoft.cn> (raw)

Hi everyone

■SQL-1
CREATE TABLE wk_mclid1(
id1 integer ,
PRIMARY KEY(id1)
);

■SQL-2
INSERT INTO wk_mclid1(id1)
VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9),(10)
GO

■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?

============================================================================================
select * from wk_mclid1 where id1= (round((random() * (10-1))::integer)
+ 1)::integer;

id1
------
9

============================================================================================
select * from wk_mclid1 where id1= (round((random() * (10-1))::integer)
+ 1)::integer;

id1
------
4
6
7
============================================================================================
select * from wk_mclid1 where id1= (round((random() * (10-1))::integer)
+ 1)::integer;

id1
------

0 record(s) selected [Fetch MetaData: 94/ms] [Fetch Data: 0/ms]
============================================================================================

thanks!




view thread (4+ messages)  latest in thread

Message-ID: <500F5870.8010400@edgesoft.cn>
Permalink:  ../500F5870.8010400@edgesoft.cn/
Also on:    postgresql.org/message-id/500F5870.8010400@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
  Subject: Re: about select use random
  In-Reply-To: <500F5870.8010400@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