Re: Random tuple?

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: Random tuple?
Дата
Msg-id 200210171613.42600.josh@agliodbs.com
обсуждение исходный текст
Ответ на Random tuple?  ("Brendan LeFebvre" <brendanl@iname.com>)
Ответы Re: Random tuple?  (Philip Hallstrom <philip@adhesivemedia.com>)
Список pgsql-novice
Brendan,

> Is there available a routine, intrinsic or otherwise, that allows for simple
> extraction of one(1) random tuple from a given table or query-result?
>
> (The specific application I had in mind was drawing a random product from a
> webstore's inventory to feature on a front or section web page).

SELECT tablea.*, random() as random_key
FROM tablea
ORDER BY random_key
LIMIT 1;

And you can modify the limit to select as many random rows as you want.

--
-Josh Berkus
 Aglio Database Solutions
 San Francisco


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

Предыдущее
От: Jon Jensen
Дата:
Сообщение: Re: Random tuple?
Следующее
От: Philip Hallstrom
Дата:
Сообщение: Re: Random tuple?