From: Tim Ellis <pvspam-postgres@hacklab.net>
To: Marc Soler <msoler@el-valles.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: About sorting rows randomly
Date: 28 Mar 2003 02:29:49 -0800
Message-ID: <1048847388.2338.6.camel@timetop> (raw)
In-Reply-To: <00f501c2f504$9b7e1180$0300a8c0@terra>
References: <00f501c2f504$9b7e1180$0300a8c0@terra>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: pvspam-postgres@hacklab.net, msoler@el-valles.com
Subject: Re: About sorting rows randomly
In-Reply-To: <1048847388.2338.6.camel@timetop>
References: <00f501c2f504$9b7e1180$0300a8c0@terra> <1048847388.2338.6.camel@timetop>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox