Re: Random Weighted Result Ordering - Mailing list pgsql-general

From Dimitri Fontaine
Subject Re: Random Weighted Result Ordering
Date
Msg-id 87r5kj9r6c.fsf@hi-media-techno.com
Whole thread Raw
In response to Random Weighted Result Ordering  (Eliot Gable <egable+pgsql-general@gmail.com>)
Responses Re: Random Weighted Result Ordering  (Eliot Gable <egable+pgsql-general@gmail.com>)
List pgsql-general
Eliot Gable <egable+pgsql-general@gmail.com> writes:

> I have a set of results that I am selecting from a set of tables which I want to return in a random weighted order
foreach priority group returned. Each row has a 
> priority column and a weight column. I sort by the priority column with 1 being highest priority. Then, for each
distinctpriority, I want to do a weighted random 
> ordering of all rows that have that same priority. I select the set of rows and pass it to a custom-built function
thatdoes the ordering. I have tested both the 
> prioritize and the random weighted ordering functions and they do exactly what I want them to do for ordering the
datathat I send them. 
>
> The problem comes from the fact that I tried to make them generalized. They take an array of a small complex type
whichholds just an arbitrary ID, the priority, 
> and the weight. The output is the same information but the rows are in
> the correct order.

I'd try having the function return just numbers in the right order, then
use that in the ORDER BY. To have those numbers, you'd still need to
join with the result of the function, tho.

Hope this helps you already, I don't have time to go deeper in the
subject!

Regards,
--
dim

pgsql-general by date:

Previous
From: Zery
Date:
Subject: Re: WINDOWS : PostgreSQL 8.4 Server Start Error
Next
From: Ravi Katkar
Date:
Subject: Do ODBC - Posgresql supports refcursor?