random

From: Jelle Ouwerkerk <jelle(at)openface(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: random
Date: 2001-03-05 19:12:15
Message-ID: Pine.NEB.4.10.10103051400050.13137-100000@what.openface.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 row using 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andrew Perrin 2001-03-05 19:22:29 Re: How do I use text script containing SQL?
Previous Message clayton cottingham 2001-03-05 19:10:26 Re: How do I use text script containing SQL?