aggregate function for median calculation

From: "Thalis A(dot) Kalfigopoulos" <thalis(at)cs(dot)pitt(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: aggregate function for median calculation
Date: 2001-06-18 18:42:24
Message-ID: Pine.LNX.4.21.0106181426130.24987-100000@aluminum.cs.pitt.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hippl,
I'm interested in calculating the median of a set of numbers. The algorithm requires that all values are known in advance (ie stored in an array). So the question is: how can I store everything first in an array so I can later process it given that I'd like this to be an aggregate function. I thought of creating an aggregate function and have the state_function() gather all the values of a group in an array and the final_function() to do the actuall median calculation on this array. But the intermmediate state cannot hold multiple values in an array (can it?)
Any ideas on how to go with this?

TIA,
thalis

Responses

Browse pgsql-general by date

  From Date Subject
Next Message will trillich 2001-06-18 18:52:56 Re: OT: Apache::Session::DBI vs postgresql? --help
Previous Message Vilson farias 2001-06-18 18:27:21 ERROR: cache lookup for userid 26 failed