Re: About sorting rows randomly

From: Tim Ellis <pvspam-postgres(at)hacklab(dot)net>
To: Marc Soler <msoler(at)el-valles(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: About sorting rows randomly
Date: 2003-03-28 10:29:49
Message-ID: 1048847388.2338.6.camel@timetop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message jeanarthur 2003-03-28 10:39:22 Requests per second ?
Previous Message Marc Soler 2003-03-28 08:32:38 About sorting rows randomly