| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Opaleye.Internal.Window
Synopsis
- newtype Window a = Window (PackMap (WndwOp, Partition) PrimExpr () a)
- runWindow :: Applicative f => Window a -> ((WndwOp, Partition) -> f PrimExpr) -> f a
- extractWindowFields :: Tag -> (WndwOp, Partition) -> PM (Bindings (WndwOp, Partition)) PrimExpr
- window :: Select (Window a) -> Select a
- makeWndw :: WndwOp -> Window (Field_ n a)
- cumulative :: Aggregator a b -> a -> Window b
- over :: Window a -> Partition -> Window a
- data Partition = Partition ![PrimExpr] ![OrderExpr]
- partitionBy :: Field_ n a -> Partition
- orderPartitionBy :: a -> Order a -> Partition
Documentation
Window is an applicative functor that represents expressions that
contain
window functions.
window can be used to evaluate these expressions over a particular query.
extractWindowFields :: Tag -> (WndwOp, Partition) -> PM (Bindings (WndwOp, Partition)) PrimExpr Source #
window :: Select (Window a) -> Select a Source #
window runs a query composed of expressions containing
window functions.
window is similar to aggregate, with the main difference being
that in a window query, each input row corresponds to one output row,
whereas aggregation queries fold the entire input query down into a single
row. To put this into a Haskell context, aggregate is to foldl
as window is to scanl.
cumulative :: Aggregator a b -> a -> Window b Source #
cumulative allows the use of aggregation functions in Window
expressions. In particular,
(when combined with cumulative sumorderPartitionBy) gives a running total,
also known as a "cumulative sum", hence the name cumulative.
over :: Window a -> Partition -> Window a infixl 1 Source #
over adds a Partition to a Window expression.
cumulativesumsalary `over`partitionBydepartment <>orderPartitionBysalary (descid)
In PostgreSQL, window functions must specify the "window" or
"partition" over which they operate. The syntax for this looks like:
SUM(salary) OVER (PARTITION BY department). The Opaleye type Partition
represents everything that comes after OVER.
Partition is a Monoid, so Partitions created with partitionBy and
orderPartitionBy can be combined using <>.
partitionBy :: Field_ n a -> Partition Source #
Restricts a window function to operate only the group of rows that share the same value(s) for the given expression(s).
orderPartitionBy :: a -> Order a -> Partition Source #
Controls the order in which rows are processed by window functions. This does not need to match the ordering of the overall query.