Selecting random row - Mailing list pgsql-general

From Michal Taborsky
Subject Selecting random row
Date
Msg-id aiduid$2e4m$1@news.hub.org
Whole thread Raw
Responses Re: Selecting random row  (Arguile <arguile@lucentstudios.com>)
List 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 by date:

Previous
From: Elielson Fontanezi
Date:
Subject: Locale Style - American numeric values to European numeric values
Next
From: "Mario Weilguni"
Date:
Subject: Re: very slow updates