Safe Haskell | None |
---|---|

Language | Haskell98 |

Perform aggregations on query results.

- aggregate :: Aggregator a b -> Query a -> Query b
- groupBy :: Aggregator (Column a) (Column a)
- sum :: Aggregator (Column a) (Column a)
- count :: Aggregator (Column a) (Column PGInt8)
- avg :: Aggregator (Column PGFloat8) (Column PGFloat8)
- max :: PGOrd a => Aggregator (Column a) (Column a)
- min :: PGOrd a => Aggregator (Column a) (Column a)
- boolOr :: Aggregator (Column PGBool) (Column PGBool)
- boolAnd :: Aggregator (Column PGBool) (Column PGBool)
- arrayAgg :: Aggregator (Column a) (Column (PGArray a))
- stringAgg :: Column PGText -> Aggregator (Column PGText) (Column PGText)
- data Aggregator a b

# Documentation

aggregate :: Aggregator a b -> Query a -> Query b Source

Given a `Query`

producing rows of type `a`

and an `Aggregator`

accepting rows of
type `a`

, apply the aggregator to the results of the query.

groupBy :: Aggregator (Column a) (Column a) Source

Group the aggregation by equality on the input to `groupBy`

.

sum :: Aggregator (Column a) (Column a) Source

Sum all rows in a group.

data Aggregator a b Source

An `Aggregator`

takes a collection of rows of type `a`

, groups
them, and transforms each group into a single row of type `b`

. This
corresponds to aggregators using `GROUP BY`

in SQL.

An `Aggregator`

corresponds closely to a `Fold`

from the
`foldl`

package. Whereas an `Aggregator`

`a`

`b`

takes each group of
type `a`

to a single row of type `b`

, a `Fold`

`a`

`b`

takes a list of `a`

and returns a single row of type `b`

.