Re: Obtaining random rows from a result set

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: Obtaining random rows from a result set
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C22215C9@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на Obtaining random rows from a result set  (Alban Hertroys <alban@magproductions.nl>)
Список pgsql-general
Alban Hertroys wrote:
> I've recently been busy improving a query that yields a fixed
> number of random records matching certain conditions.

> Dear Santa,
>
> I'd like my database to have functionality analogue to how
> LIMIT works,
> but for other - non-sequential - algorithms.
>
> I was thinking along the lines of:
>
>     SELECT *
>       FROM table
>      WHERE condition = true
>      RANDOM 5;

Ho, ho, ho.

SELECT *
FROM table
WHERE condition = true
ORDER BY hashfloat8(random())
LIMIT 5;

Yours,
Laurenz Albe

В списке pgsql-general по дате отправления:

Предыдущее
От: "Phoenix Kiula"
Дата:
Сообщение: Re: URGENT: Whole DB down ("no space left on device")
Следующее
От: Csaba Nagy
Дата:
Сообщение: Re: Obtaining random rows from a result set