Re: min,max aggregate functions
От | Dann Corbit |
---|---|
Тема | Re: min,max aggregate functions |
Дата | |
Msg-id | D90A5A6C612A39408103E6ECDD77B82906F3F6@voyager.corporate.connx.com обсуждение исходный текст |
Список | pgsql-hackers |
-----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 <<---------------------------------------------------------------------
В списке pgsql-hackers по дате отправления: