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 00:33:45 |
Message-ID: | 3F611469.5070606@fireserve.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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?
Joseph Shraibman wrote:
> Is there a way to get random rows besides ORDER BY random()? The
> problem with ORDER BY random() is that is has to get all the rows from
> the table before the results are returned.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if
> your
> joining column's datatypes do not match
>
From | Date | Subject | |
---|---|---|---|
Next Message | Joseph Shraibman | 2003-09-12 00:36:09 | Re: selecting random rows |
Previous Message | Bruce Momjian | 2003-09-12 00:26:56 | Re: selecting random rows |