Selecting random row

Поиск
Список
Период
Сортировка
От Michal Taborsky
Тема Selecting random row
Дата
Msg-id aiduid$2e4m$1@news.hub.org
обсуждение исходный текст
Ответы Re: Selecting random row
Список pgsql-general
Hi everyone,

I am facing a performance problem with selecting a random row from a table.
I do it like this:

SELECT * FROM table ORDER BY random() LIMIT 1

But it seems that the random() function is quite slow and backend apparently
evaluates the function for all rows (which is logical). On a table with few
thousand rows it takes seconds. Does anybody know a better solution to
selecting one (or more) random rows from a table ?

Thanks for any ideas,
Michal



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