Re: Selecting random row - Mailing list pgsql-general

From Doug McNaught
Subject Re: Selecting random row
Date
Msg-id m3d6t11bd5.fsf@varsoon.wireboard.com
Whole thread Raw
In response to Re: Selecting random row  (Arguile <arguile@lucentstudios.com>)
Responses Re: Selecting random row
List 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

pgsql-general by date:

Previous
From: "David Blood"
Date:
Subject: Re: [HACKERS] []performance issues
Next
From: Cédric Dufour
Date:
Subject: b1 OR b2 <-> ( CASE WHEN b1 THE true ELSE b2 END ): performance bottleneck on logical OR