From: | Greg Smith <gsmith(at)gregsmith(dot)com> |
---|---|
To: | Kashmir <kashmir_us_1999(at)yahoo(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: user defined aggregate for percentile calculations |
Date: | 2009-04-06 23:03:24 |
Message-ID: | alpine.GSO.2.01.0904061852030.5640@westnet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sun, 5 Apr 2009, Kashmir wrote:
> would it possible at all to create a percentile-aggregate in pgres?
I normally just do this right in the database without specifically
accelerating it with an aggregate. Not very efficient but it works fine
for reasonably sized data sets that fit into the database cache. Here's
an example that computes some statistics about temporary data in a table
named "timing" into a summary statistics table named tests:
update tests set trans=(select count(*) from timing);
update tests set
avg_latency=(select avg(latency) from timing),
max_latency=(select max(latency) from timing),
percentile_90_latency=
(select latency from timing
order by latency offset (round(0.90*trans)) limit 1);
Even if that's not efficient enough for your final app, you might use that
sort of thing as a prototype until you get a better implementation, rather
than dropping into Perl.
--
* Greg Smith gsmith(at)gregsmith(dot)com http://www.gregsmith.com Baltimore, MD
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2009-04-06 23:04:30 | Re: tsearch2 dictionary for statute cites |
Previous Message | Alvaro Herrera | 2009-04-06 22:49:14 | Re: user defined aggregate for percentile calculations |