| From: | Dennis Gearon <gearond(at)fireserve(dot)net> |
|---|---|
| To: | Joseph Shraibman <jks(at)selectacast(dot)net> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: selecting random rows |
| Date: | 2003-09-12 14:01:39 |
| Message-ID: | 3F61D1C3.3050709@fireserve.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Joseph Shraibman wrote:
> 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.
>
>
But it only caches the keys in the one sub select, NOT the whole row
that you eventually want. I have not idea whether you just want the
primary key, or several fields.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Manfred Koizar | 2003-09-12 14:02:34 | Re: State of Beta 2 |
| Previous Message | Manfred Koizar | 2003-09-12 13:52:36 | Re: State of Beta 2 |