Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id E3E0E9F9FB1 for ; Sat, 18 Nov 2006 13:52:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 98443-09 for ; Sat, 18 Nov 2006 13:52:21 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.188]) by postgresql.org (Postfix) with ESMTP id 07B219F9B3F for ; Sat, 18 Nov 2006 13:52:20 -0400 (AST) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu1) with ESMTP (Nemesis), id 0MKwpI-1GlUMU359P-0000i4; Sat, 18 Nov 2006 18:52:19 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1GlUMS-0000Ox-00 for pgsql-sql@postgresql.org; Sat, 18 Nov 2006 18:52:16 +0100 Date: Sat, 18 Nov 2006 18:52:16 +0100 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: Random() Message-ID: <20061118175216.GA1444@a-kretschmer.de> References: <55c095e90611161031h7a1ce42chd9a59a53ba7e7028@mail.gmail.com> <20061116191632.GA21285@a-kretschmer.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! User-Agent: Mutt/1.5.9i X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/196 X-Sequence-Number: 26848 am Sat, dem 18.11.2006, um 23:02:33 +0530 mailte Rajesh Kumar Mallah folgendes: > >select from order by random() limit 1; > > This query will tend to get slower as the table grows because of the > sorting. Right. > > it possible to get a row from a random offset > how about > > select from limit 1 offset 20000*random() ; For instance, you have a table with only 500 rows and random() returns 0.999? In other words: in think, this is a bad idea, unless you use a constant for the offset-calculation thats not larger than the number of rows in this table. For this, you need this value, but select count(1) from table force a seqscan -> slow. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47215, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net