Re: selecting random rows

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: selecting random rows
Дата
Msg-id 200309120026.h8C0Qu513895@candle.pha.pa.us
обсуждение исходный текст
Ответ на selecting random rows  (Joseph Shraibman <jks@selectacast.net>)
Список 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 по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: NFS performance tuning
Следующее
От: Dennis Gearon
Дата:
Сообщение: Re: selecting random rows