Thursday, February 05. 2009

In our August 2008/ September 2008 issue we demonstrated the power of PostgreSQL to create median and MS Access-like first and last aggregate functions in
SQL language. In this article we shall demonstrate how to create aggregates with Python. We shall
call this function agg_plot. What it will do is plot each grouping of data and return a plot for each grouping. The steps
we covered in those articles can be applied here.

Creating Aggregate functions with PL/Python

Our basic approach is as follows:

Since PL/Python does not support arrays as input, our aggregator will form a pipe delimeted list inputs
as a string using plot_databuild function (which although we wrote it in python need not be and probably more efficient to write in plpgsql

As the final step of the aggregation, this is fed to our plot_numbers function -- which converts this to an array of strings and then converts to an array of
numbers to be fed to the plotter

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.Enter the string from the spam-prevention image above: