-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Wednesday, February 27, 2002 9:47 AM
To: Oleg Bartunov
Cc: Pgsql Hackers
Subject: Re: [HACKERS] min,max aggregate functions 


Oleg Bartunov <oleg@sai.msu.su> writes:
> AFAIK, it's required to write min(),max() aggregate functions for
> user-defined types even if compare function is already defined for
> this type. Is't possible to get these functions working for
> such user-defined types automatically ?

Doesn't really seem worth the trouble.  We'd need some sort of notion
of a generic aggregate function; and even then, you'd have to tell the
system what comparison function to use for your datatype.
>>---------------------------------------------------------------------
Here is a C++ template summation tool I created, and made public domain:
ftp://cap.connx.com/pub/tournament_software/Kahan.Hpp

It is a far more effective technique than just adding the numbers up.

You can have different types for the input data and the accumulator.
So (for instance) you can sum floats into a double or doubles into a
long double or whatever.  This allows a simple way to prevent overflows
and also greatly increases accuracy with very little additional cost
in computation.

Now, PostgreSQL is C and not C++, but the idea can be translated into
ordinary C code.

If you adopt some fundamental large type for the accumulator, and the
user type has a conversion into that type, then you could make a
generic accumulator very easily.

This template does all kinds of statistics, and might also prove useful:
ftp://cap.connx.com/pub/tournament_software/STATS.HPP
<<---------------------------------------------------------------------

Wed, 27 Feb 2002 13:05:52 -0800
"Dann Corbit" <DCorbit@connx.com>
Re: min,max aggregate functions 