Re: finding medians - Mailing list pgsql-hackers

From Josh Berkus
Subject Re: finding medians
Date
Msg-id 200205301330.09537.josh@agliodbs.com
Whole thread Raw
In response to finding medians  (Josh Burdick <jburdick@gradient.cis.upenn.edu>)
List pgsql-hackers
Josh,

>     At the end of this message is some code I used to find medians.
>     It's kind of a hack, but approximately works, and is intended as a
> somewhat awkward stopgap for people who need to use medians.  It
> illustrates the limitations of the current aggregate function setup,
> which works so nicely for avg() and stddev().

Actually, finding the median is one of the classic SQL problems.  You can't do
it without 2 passes through the data set, disallowing the use of traditional
aggregate functions.  Joe Celko has half a chapter devoted to various methods
of finding the median.

Can I talk you into submitting your code to Techdocs?  I'd love to have it
somewhere where it won't get buried in the mailing list archives.

--
-Josh Berkus



pgsql-hackers by date:

Previous
From: Josh Burdick
Date:
Subject: finding medians
Next
From: "Dann Corbit"
Date:
Subject: Re: finding medians