Adding Aggregates


You have learned how to define operators and datatypes. In this section, you explore aggregates. You have already learned the five important aggregate functions ( SUM , AVG , MAX , MIN , and COUNT ), which are defined for nearly all datatypes in PostgreSQL. These functions are called aggregate functions because they summarize the results of a query rather than listing all the rows in the result of the query.

Now that we have defined a new datatype, it might also be useful to define an aggregate function for it. Unfortunately, it is far more complex to write aggregate functions than to write the functions used for the operator, because more than one row is involved in the operation. Full coverage of how aggregate functions can be defined in PostgreSQL is far beyond the scope of this book.

If you want to find out how PostgreSQL's on-board aggregate functions have been implemented, check out $SRC_ROOT/src/backend/ utils /adt. In this directory, you can find a lot of files containing a lot of code that make all those wonderful datatypes work the way they do.



PostgreSQL Developer's Handbook2001
PostgreSQL Developer's Handbook2001
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 125

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net