Selecting random row
Michal Taborsky <michal@taborsky.cz>
From: "Michal Taborsky" <michal@taborsky.cz>
To: pgsql-general@postgresql.org
Date: 2002-08-02T12:38:44Z
Lists: 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