pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedAbout sorting rows randomly
4+ messages / 4 participants
[nested] [flat]
* About sorting rows randomly
@ 2003-03-28 08:32 Marc Soler <msoler@el-valles.com>
0 siblings, 3 replies; 4+ messages in thread
From: Marc Soler @ 2003-03-28 08:32 UTC (permalink / raw)
To: pgsql-admin
Hi all
It's possible to return rows randomly sorted?
Something like this:
Select * from table order by random
Thanks
--
Marc Soler
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: About sorting rows randomly
@ 2003-03-28 10:29 Tim Ellis <pvspam-postgres@hacklab.net>
parent: Marc Soler <msoler@el-valles.com>
2 siblings, 0 replies; 4+ messages in thread
From: Tim Ellis @ 2003-03-28 10:29 UTC (permalink / raw)
To: Marc Soler <msoler@el-valles.com>; +Cc: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: About sorting rows randomly
@ 2003-03-28 12:01 Ian Barwick <ian@barwick.de>
parent: Marc Soler <msoler@el-valles.com>
2 siblings, 0 replies; 4+ messages in thread
From: Ian Barwick @ 2003-03-28 12:01 UTC (permalink / raw)
To: Marc Soler <msoler@el-valles.com>; pgsql-admin
On Friday 28 March 2003 09:32, Marc Soler wrote:
> Hi all
>
> It's possible to return rows randomly sorted?
>
> Something like this:
>
> Select * from table order by random
SELECT foo, bar, random() AS rand FROM my_table ORDER BY rand
Ian Barwick
barwick@gmx.net
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: About sorting rows randomly
@ 2003-03-28 13:56 Peter Eisentraut <peter_e@gmx.net>
parent: Marc Soler <msoler@el-valles.com>
2 siblings, 0 replies; 4+ messages in thread
From: Peter Eisentraut @ 2003-03-28 13:56 UTC (permalink / raw)
To: Marc Soler <msoler@el-valles.com>; +Cc: pgsql-admin
Marc Soler writes:
> It's possible to return rows randomly sorted?
select * from table order by random();
--
Peter Eisentraut peter_e@gmx.net
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-03-28 13:56 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-03-28 08:32 About sorting rows randomly Marc Soler <msoler@el-valles.com>
2003-03-28 10:29 ` Tim Ellis <pvspam-postgres@hacklab.net>
2003-03-28 12:01 ` Ian Barwick <ian@barwick.de>
2003-03-28 13:56 ` Peter Eisentraut <peter_e@gmx.net>
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