The Art of PostgreSQL, one article at a time

The Art of PostgreSQL blog introduces PostgreSQL concepts that are useful for application developers. The content of this blog is either extracted from the published book, or written in preparation for book material. Reading this blog, you can enjoy The Art of PostgreSQL content one piece at a time!

Remember to practice what you learn here and elsewhere!


What is an SQL Aggregate?

In our previous articles we had a look at What is an SQL relation? and What is a SQL JOIN?. Today, I want to show you what is an aggregate in SQL.

You might have heard about Map/Reduce when Google made it famous, or maybe some years before, or maybe some years later. The general processing functions map and reduce where invented a very long time ago. The novelty from the advertising giant was in using them in a heavily distributed programming context.

With map you apply the same processing to every object in a collection. With reduce, you compute a result per collection of object. In SQL we know how to do that too, and we call that an aggregate.