From: Jeff Herrin <jeff@alternateimage.com>
To: pgsql-sql@postgresql.org
Subject: consistent random order
Date: Wed, 29 Nov 2006 11:38:17 -0500 (EST)
Message-ID: <15697722.58781164818297562.JavaMail.root@srv161.carpathiahost.net> (raw)
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. Ideally I would need to do this:
ORDER BY myRandomUDF(1234)
or
ORDER BY myRandomUDF(2345)
Where the argument acts like a seed that always returns a consistent pseudo-random set. That way, when I get to the 2nd page, i know i'm getting the dataset back in the same order that I had on page 1, and the offset works like normal. Is this even realistically possible?
Thanks,
Jeff Herrin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: jeff@alternateimage.com
Subject: Re: consistent random order
In-Reply-To: <15697722.58781164818297562.JavaMail.root@srv161.carpathiahost.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox