min,max aggregate functions
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
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
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
-----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
<<---------------------------------------------------------------------
Import Notes
Resolved by subject fallback