Re: min,max aggregate functions

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Oleg Bartunov" <oleg(at)sai(dot)msu(dot)su>
Cc: "Pgsql Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: min,max aggregate functions
Date: 2002-02-27 21:05:52
Message-ID: D90A5A6C612A39408103E6ECDD77B82906F3F6@voyager.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

-----Original Message-----
From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)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(at)sai(dot)msu(dot)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
<<---------------------------------------------------------------------

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2002-02-27 21:08:37 Re: Oracle vs PostgreSQL in real life
Previous Message Hannu Krosing 2002-02-27 20:48:17 Re: Oracle vs PostgreSQL in real life