Re: About sorting rows randomly - Mailing list pgsql-admin

From Tim Ellis
Subject Re: About sorting rows randomly
Date
Msg-id 1048847388.2338.6.camel@timetop
Whole thread Raw
In response to About sorting rows randomly  ("Marc Soler" <msoler@el-valles.com>)
Responses Requests per second ?  (jeanarthur@eurovox.fr)
List pgsql-admin
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


pgsql-admin by date:

Previous
From: "Marc Soler"
Date:
Subject: About sorting rows randomly
Next
From: jeanarthur@eurovox.fr
Date:
Subject: Requests per second ?