Re: Selecting random row

Doug McNaught <doug@wireboard.com>

From: Doug McNaught <doug@wireboard.com>
To: "Michal Taborsky" <michal@taborsky.cz>
Cc: pgsql-general@postgresql.org
Date: 2002-08-02T16:20:06Z
Lists: pgsql-general
"Michal Taborsky" <michal@taborsky.cz> writes:

> This does decrease the the cost, but only very little (10500 -> 9800), which
> is not the solution. That thing with sequential index might work for some
> cases, that is true. Unfortunately not in this one, because I actually do
> not select random row from a table, but from a complex select query
> resultset. But thanks for the suggestions.

Why not

SELECT * FROM table LIMIT 1 OFFSET random(SELECT count(*) FROM TABLE);

I don't know if this is the exact syntax but you get the idea...

-Doug