Hi,
> Right now (in perl), I select the complete list of id's into a @list, do
> a $id = $list[rand(@list)] and have the right row. But this seems to be
> very time-consuming, and I would like to have it done completely in the
> Pg-database.
You can order by random and get the first row:
select
id
from
table
where
agr>=60 and sex = 'm'
order by
random()
limit
1
;
This will also compute the whole result set - well, you have to in order
to get the value set to select from - but at least you don't have to
pull all data into your application tier.
With kind regards / Mit freundlichem Gruß
Holger Klawitter
--
Holger Klawitter
holger@klawitter.de http://www.klawitter.de