Here is Josh Berkus' solution for randomly picking a single row from a
query. I think the FAQ (www.postgresql.org/docs/faqs.FAQ.html#item4.1)
could be updated with a link to this solution, which is more practical
for large queries.
www.powerpostgresql.com/Random_Aggregate
Here is a discus
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 t
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.
Yes, I think one person's idea was to assign a unique value to every
row, then do:
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 slo