Re: selecting random rows - Mailing list pgsql-general

From Bruce Momjian
Subject Re: selecting random rows
Date
Msg-id 200309120026.h8C0Qu513895@candle.pha.pa.us
Whole thread Raw
In response to selecting random rows  (Joseph Shraibman <jks@selectacast.net>)
List pgsql-general
Joseph Shraibman wrote:
> Is there a way to get random rows besides ORDER BY random()?  The problem with ORDER BY
> random() is that is has to get all the rows from the table before the results are returned.

Yes, I think one person's idea was to assign a unique value to every
row, then do:

    WHERE col > random()
    ORDER BY col
    LIMIT 1

or something like that.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: NFS performance tuning
Next
From: Dennis Gearon
Date:
Subject: Re: selecting random rows