width_bucket function for timestamps - Mailing list pgsql-hackers

From Jeremy Drake
Subject width_bucket function for timestamps
Date
Msg-id Pine.BSO.4.64.0610082214290.31431@resin.csoft.net
Whole thread Raw
Responses Re: width_bucket function for timestamps  ("Jim C. Nasby" <jim@nasby.net>)
List pgsql-hackers
I just came across this code I wrote about a year ago which implements a
function equivilant to width_bucket for timestamps.

I wrote this when I was trying to plot some data over time, and I had more
points than I needed.  This function allowed me to create a pre-determined
number of "bins" to average the data inside of so that I could get a sane
number of points.  Part of the problem was that there were so many data
points, that a sql implementation of the function (or plpgsql, I forget,
it was a year ago) was painfully slow.  This C function provided much
better performance than any other means at my disposal.

I wanted to share this code since it may be useful for someone else, but I
don't know exactly what to do with it.  So I am putting it out there, and
asking what the proper home for such a function might be.  I believe it
would be generally useful for people, but it is so small that it hardly
seems like a reasonable pgFoundry project.  Maybe there is a home for such
a thing in the core distribution in a future release?

The code can be found at
http://www.jdrake.com/postgresql/bintimestamp.tar.gz for a buildable PGXS
module, or I attached just the C code.  There is no documentation, the
parameters work the same as the width_bucket function.  The code is not
necessarily the most readable in the world, I was trying to get as much
speed out of it as possible, since I was calling it over a million times
as a group by value.

Thanks for any pointers...

-- 
Fortune's Office Door Sign of the Week:
Incorrigible punster -- Do not incorrige.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Upgrading a database dump/restore
Next
From: "Dave Page"
Date:
Subject: Re: Casting to money