Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 9DEBE12DEACC for ; Mon, 23 Apr 2012 11:53:21 -0300 (ADT) Received: from gwmta.wicourts.gov ([165.219.244.99] helo=gw.wicourts.gov) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SMKdk-0004el-1d for pgsql-bugs@postgresql.org; Mon, 23 Apr 2012 14:53:21 +0000 Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Mon, 23 Apr 2012 09:53:07 -0500 Message-Id: <4F95267F020000250004723E@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.2 Date: Mon, 23 Apr 2012 09:53:03 -0500 From: "Kevin Grittner" To: , Subject: Re: BUG #6607: Strange select behavior References: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201204/132 X-Sequence-Number: 32883 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: select t.* from (select (random()* 100000)::integer) n(r) join testt t on (t.id = n.r); By the way, you might want to tweak that random number before casting it to int, or you might not get *any* rows back: test=# select ('0.0000000001'::float * 100000)::int; int4 ------ 0 (1 row) Maybe something like: (select floor(random() * 100000)::int + 1) -Kevin