Re: consistent random order

From: Jeff Herrin <jeff(at)alternateimage(dot)com>
To: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: consistent random order
Date: 2006-11-29 17:32:56
Message-ID: 25133466.59111164821576601.JavaMail.root@srv161.carpathiahost.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I don't think cursors are going to help in this case. The order by random() is still going to give different result sets on different pages.

Jeff

----- Original Message -----
From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Sent: Wednesday, November 29, 2006 12:27:42 PM GMT-0500 US/Eastern
Subject: Re: [SQL] consistent random order

Jeff Herrin <jeff(at)alternateimage(dot)com> schrieb:

> I am returning results ordered randomly using 'order by random()'. My issue has
> to do with page numbers in our web application. When I hit the 2nd page and
> retrieve results with an offset, ordering by random() isn't really what I want
> since I will often receive results that were on the 1st page (they get re-
> randomized).
>
> I'm looking for a way to order in a controled random order. Maybe a UDF.

I think you are searching for CURSORs.

18:25 < akretschmer> ??cursor
18:25 < rtfm_please> For information about cursor
18:25 < rtfm_please> see http://www.postgresql.org/docs/current/static/plpgsql-cursors.html
18:25 < rtfm_please> or http://www.postgresql.org/docs/current/static/sql-declare.html

With a CURSOR, you get one result-set and can walk through this result.

Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2006-11-29 17:53:16 Re: Subselects in CHECK clause ...
Previous Message Jeff Herrin 2006-11-29 17:30:57 Re: consistent random order