Re: selecting random rows

From: Joseph Shraibman <jks(at)selectacast(dot)net>
To: Dennis Gearon <gearond(at)fireserve(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: selecting random rows
Date: 2003-09-12 00:36:09
Message-ID: 3F6114F9.4010104@selectacast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dennis Gearon wrote:
> If you have a nice small Primary key on the table, you can so something
> like this:
>
> SELECT field_list
> FROM table
> WHERE primary_key IN(
> SELECT primary_key,
> FROM table
> ORDER by RANDOM()
> LIMIT your_limit);
>
> This may not be the exact sequence, and there is some workarounds for
> some slowness in the IN() keyword. Others may comment at will, and
> polish this up?
>
What exactly does that do for me? Postgres still has to go over the whole table to get
the primary keys.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joseph Shraibman 2003-09-12 00:53:53 Re: NFS performance tuning
Previous Message Dennis Gearon 2003-09-12 00:33:45 Re: selecting random rows