Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 8F1139F9ECF for ; Thu, 30 Nov 2006 06:04:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 54936-07 for ; Thu, 30 Nov 2006 06:04:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from ipmail02.adl2.internode.on.net (ipmail02.adl2.internode.on.net [203.16.214.141]) by postgresql.org (Postfix) with ESMTP id 845059F946B for ; Thu, 30 Nov 2006 06:04:43 -0400 (AST) Received: from ppp247-71.static.internode.on.net (HELO [192.168.8.200]) ([203.122.247.71]) by ipmail02.adl2.internode.on.net with ESMTP; 30 Nov 2006 20:34:40 +1030 X-IronPort-AV: i="4.09,478,1157293800"; d="scan'208"; a="53608260:sNHT40038005" Message-ID: <456EACB6.4020702@007Marketing.com> Date: Thu, 30 Nov 2006 20:34:38 +1030 From: Shane Ambler User-Agent: Thunderbird 1.5.0.7 (Macintosh/20060909) MIME-Version: 1.0 To: Jeff Herrin CC: Andreas Kretschmer , pgsql-sql@postgresql.org Subject: Re: consistent random order References: <25133466.59111164821576601.JavaMail.root@srv161.carpathiahost.net> In-Reply-To: <25133466.59111164821576601.JavaMail.root@srv161.carpathiahost.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/288 X-Sequence-Number: 26940 Jeff Herrin wrote: > I don't think cursors are going to help in this case. The order by random() is still going to give different result sets on different pages. > > Jeff A cursor will maintain the order it was created with until it is disposed of. It won't work with a web app though as each page will come from a different connection in the available pool (or created for each page) meaning you will loose the cursor between pages. I would think you want to look at having a sort column that has a random number in it that is used for sorting. mysortcol integer default random() or maybe update the column a couple of times a day to keep the variety you seem to be after. > ----- Original Message ----- > From: Andreas Kretschmer > To: pgsql-sql@postgresql.org > Sent: Wednesday, November 29, 2006 12:27:42 PM GMT-0500 US/Eastern > Subject: Re: [SQL] consistent random order > > Jeff Herrin schrieb: > >> I am returning results ordered randomly using 'order by random()'. My issue has >> to do with page numbers in our web application. When I hit the 2nd page and >> retrieve results with an offset, ordering by random() isn't really what I want >> since I will often receive results that were on the 1st page (they get re- >> randomized). >> >> I'm looking for a way to order in a controled random order. Maybe a UDF. > > I think you are searching for CURSORs. > > 18:25 < akretschmer> ??cursor > 18:25 < rtfm_please> For information about cursor > 18:25 < rtfm_please> see http://www.postgresql.org/docs/current/static/plpgsql-cursors.html > 18:25 < rtfm_please> or http://www.postgresql.org/docs/current/static/sql-declare.html > > With a CURSOR, you get one result-set and can walk through this result. > > > Andreas -- Shane Ambler pgSQL@007Marketing.com Get Sheeky @ http://Sheeky.Biz