random - Mailing list pgsql-sql

From Jelle Ouwerkerk
Subject random
Date
Msg-id Pine.NEB.4.10.10103051400050.13137-100000@what.openface.ca
Whole thread Raw
Responses Re: random
Re: random
List pgsql-sql
Hi

What would be the best way to select a random row from a result set?

Possibilities:

1) o get the total number of rows using count()  o generate a random number between 1 and the total  o select the n'th
rowusing OFFSET
 

2) o get the total number of rows using count()  o generate a random number between 1 and the total  o fetch n times

Option 1 uses 'OFFSET' which is a database-specific keyword, which is
probably bad. 

Also, is there a way to randomize the order of a result set?

Thanks in advance

Jelle Ouwerkerk
Software Developer 
Openface Internet Inc.
Montreal, Quebec, Canada
http://www.openface.ca



pgsql-sql by date:

Previous
From: David Olbersen
Date:
Subject: Re: How do I use text script containing SQL?
Next
From: wade
Date:
Subject: pl/pgsql and returning rows