Received: from sysadmin.chi.wdr.com (sysadmin.chi.ubswarburg.com [146.180.1.66]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f1J5lNx04760 for ; Mon, 19 Feb 2001 00:47:23 -0500 (EST) (envelope-from devin@sysadmin.chi.wdr.com) Received: from devin by sysadmin.chi.wdr.com with local (Exim 3.12 #2) id 14UjAN-0003Oc-00; Sun, 18 Feb 2001 23:47:19 -0600 Date: Sun, 18 Feb 2001 23:47:14 -0600 (CST) From: Tod McQuillin X-X-Sender: To: Christopher Sawtell cc: Subject: Re: Bug? Me or PostgreSQL. In-Reply-To: <01021917450300.27125@berty> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200102/303 X-Sequence-Number: 1499 On Mon, 19 Feb 2001, Christopher Sawtell wrote: > How can this happen? > > chris=# select name from boys_names where > boys_names.number=(random()*225+1)::int4; > name > -------- > Fred > Gunnar > Manuel > Rainer > (4 rows) It's not clear what you expected to see -- I'll guess you expected only one row returned. But random() is being called once for every row in the table -- it's not surprising (if you have a lot of rows) that it comes up with a match more than once. Sometimes it might even return no rows at all. SQL is not the best language for picking random members of a set. You're better off picking a random number in a procedural language and passing that number as a constant to an embedded SQL query. -- Tod McQuillin