min,max aggregate functions

Started by Oleg Bartunovalmost 24 years ago4 messages
#1Oleg Bartunov
oleg@sai.msu.su

Tom,

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 ?

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Oleg Bartunov (#1)
Re: 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.

regards, tom lane

#3Oleg Bartunov
oleg@sai.msu.su
In reply to: Tom Lane (#2)
Re: min,max aggregate functions

On Wed, 27 Feb 2002, Tom Lane wrote:

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.

I was just curious. It's always possible to use 'order by desc limit 1'
for max() function.

So, nobody is working on aggregates.

regards, tom lane

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

#4Dann Corbit
DCorbit@connx.com
In reply to: Oleg Bartunov (#3)
Re: min,max aggregate functions

-----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
<<---------------------------------------------------------------------