Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 48CA59FB453 for ; Fri, 27 Jul 2007 04:56:30 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 31964-02 for ; Fri, 27 Jul 2007 04:56:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from pat.uio.no (pat.uio.no [129.240.10.15]) by postgresql.org (Postfix) with ESMTP id DD3679FB310 for ; Fri, 27 Jul 2007 04:56:25 -0300 (ADT) Received: from mail-mx5.uio.no ([129.240.10.46]) by pat.uio.no with esmtp (Exim 4.67) (envelope-from ) id 1IEKgP-0007Cd-AU; Fri, 27 Jul 2007 09:56:21 +0200 Received: from inhaca.uio.no ([129.240.202.141]) by mail-mx5.uio.no with esmtp (Exim 4.67) (envelope-from ) id 1IEKgO-0005t7-SO; Fri, 27 Jul 2007 09:56:21 +0200 Message-ID: <46A9A524.7000009@usit.uio.no> Date: Fri, 27 Jul 2007 09:56:20 +0200 From: Tommy Gildseth User-Agent: Thunderbird 2.0.0.0 (X11/20070326) MIME-Version: 1.0 To: Stefan Zweig CC: pgsql-sql@postgresql.org Subject: Re: strange result for select * from table where id=random()*900 References: <156384696@web.de> In-Reply-To: <156384696@web.de> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-UiO-Spam-info: not spam, SpamAssassin (score=-4.9, required=12.0, autolearn=disabled, AWL=0.075, UIO_MAIL_IS_INTERNAL=-5) X-UiO-Scanned: 8D4019D34C72E341D46B574139D1F879D008E36F X-UiO-SPAM-Test: remote_host: 129.240.202.141 spam_score: -48 maxlevel 200 minaction 2 bait 0 mail/h: 2 total 154 max/h 38 blacklist 0 greylist 0 ratelimit 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200707/165 X-Sequence-Number: 28900 On 07/27/2007 09:48 AM, Stefan Zweig wrote: > hi list, > > this is my query: > > select > * > from _g2977 > where > id=floor(random() * (900)); > > in table _g2977 i have id(s) from 1 up to 900. i just want to select one random dataset by the above query but i does not work. > > actually i get sometime zero, sometimes one, sometimes two and sometimes even three results back from the above query although i thought it should give only one random dataset from the table. random() isn't immutable, so it's re-calculated for every row. Try f.ex this instead: SELECT * FROm _g2977 ORDER BY random() LIMIT 1 -- Tommy Gildseth DBA, Gruppe for databasedrift Universitetet i Oslo, USIT m: +47 45 86 38 50 t: +47 22 85 29 39