Skip site navigation (1) Skip section navigation (2)

Re: randomized order in select?

From: "Iain" <iain(at)mst(dot)co(dot)jp>
To: "Enver ALTIN" <enver(dot)altin(at)frontsite(dot)com(dot)tr>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: randomized order in select?
Date: 2004-03-11 05:31:26
Message-ID: 009301c4072a$19b28fd0$7201a8c0@mst1x5r347kymb (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
If you have a lot of tips, you could create a unique indexed tip number
column. Select the highest tip number using:

select tip_number from tips order by tip_number desc limit 1;

Then generate a random number and select using that tip_number.

Of course, you would have to allow for the possibility of missing tip
numbers, by repeating the random number generation/read sequence until you
find something. Since the tip_number isn't the PK of the table, you can
regenerate the tip numbers to eliminate holes from deletions any time you
like. Just reset the sequence to 1 and update all rows with the

Sounds like a lot of work to me though...

In response to


pgsql-sql by date

Next:From: Tom LaneDate: 2004-03-11 06:40:06
Subject: Re: randomized order in select?
Previous:From: azwaDate: 2004-03-11 01:51:08
Subject: Re: designer tool connect to PostgreSQL

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group