X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id CFC66476349 for ; Fri, 28 Mar 2003 05:30:05 -0500 (EST) Received: from hacklab.net (h-68-164-245-144.SNVACAID.covad.net [68.164.245.144]) by postgresql.org (Postfix) with SMTP id B06A0476344 for ; Fri, 28 Mar 2003 05:30:03 -0500 (EST) Received: (qmail 6629 invoked by uid 421); 28 Mar 2003 10:25:29 -0000 Received: from pvspam-postgres@hacklab.net by hacklab.net with qmail-scanner-0.93 (. Clean. Processed in 0.98045 secs); 28/03/2003 02:25:28 Received: from localhost (antispam@127.0.0.1) by localhost with SMTP; 28 Mar 2003 10:25:28 -0000 Subject: Re: About sorting rows randomly From: Tim Ellis To: Marc Soler Cc: pgsql-admin@postgresql.org In-Reply-To: <00f501c2f504$9b7e1180$0300a8c0@terra> References: <00f501c2f504$9b7e1180$0300a8c0@terra> Content-Type: text/plain Organization: PostgreSQL Admin Message-Id: <1048847388.2338.6.camel@timetop> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2-1mdk Date: 28 Mar 2003 02:29:49 -0800 Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-34.8 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT_XIMIAN autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/476 X-Sequence-Number: 8116 On Fri, 2003-03-28 at 00:32, Marc Soler wrote: > It's possible to return rows randomly sorted? > Something like this: > Select * from table order by random The way I've accomplished this in the past is to create an extra column, call it "randNum," populate it with random numbers, then order by that column. If you don't care how strong the "randomness" is, you can sort by an arbitrary column that has a lot of variation, say a foreign key column ID. I've also seen the logic moved into the application: select the values into an array, and randomly traverse the array. -- Tim Ellis Senior Database Architect and author, tedia2sql (http://tedia2sql.tigris.org) If this helped you, http://svcs.affero.net/rm.php?r=philovivero