Thread: About sorting rows randomly

About sorting rows randomly

From
"Marc Soler"
Date:
Hi all

It's possible to return rows randomly sorted?

Something like this:

Select * from table order by random

Thanks
--
Marc Soler


Re: About sorting rows randomly

From
Tim Ellis
Date:
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


Requests per second ?

From
jeanarthur@eurovox.fr
Date:
H,

Is there a simple way to know how many request per second
(average) my PG database is currently handling ??

thank you !

jean-arthur silve






Jean-Arthur Silve
EuroVox
4, Place Félix Eboué
75583 Paris Cedex 12
T : +33 1 44670505
F : +33 1 44670519


Re: About sorting rows randomly

From
Peter Eisentraut
Date:
Marc Soler writes:

> It's possible to return rows randomly sorted?

select * from table order by random();

--
Peter Eisentraut   peter_e@gmx.net


Re: Requests per second ?

From
Robert Treat
Date:
Don't remember what I wrote this for, but IIRC it outputs the current
transaction counter every 1 sec, which you can then use to determine the
number of transactions per second.

#!/bin/bash

while true
do sleep 1; psql -U postgres mydb -c "SELECT age(datfrozenxid) FROM
pg_database where datname='mydb'";
done;

I'm sure you can use this to come up with something more robust.

Robert Treat


On Fri, 2003-03-28 at 05:39, jeanarthur@eurovox.fr wrote:
> H,
>
> Is there a simple way to know how many request per second
> (average) my PG database is currently handling ??
>
> thank you !
>
> jean-arthur silve


Re: About sorting rows randomly

From
Ian Barwick
Date:
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