on dev help sign in
window docs
6e3af05Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Window.hs+11−1
@@ -100,7 +100,9 @@ data WindowDefinition outer commons grp schemas params from where
100 WindowDefinition
100 WindowDefinition
101 :: SOP.SListI bys
101 :: SOP.SListI bys
102 => NP (Expression outer commons grp schemas params from) bys
102 => NP (Expression outer commons grp schemas params from) bys
103+ -- ^ partitions
103 -> [SortExpression outer commons grp schemas params from]
104 -> [SortExpression outer commons grp schemas params from]
105+ -- ^ ordering
104 -> WindowDefinition outer commons grp schemas params from
106 -> WindowDefinition outer commons grp schemas params from
105
107
106instance OrderBy WindowDefinition where
108instance OrderBy WindowDefinition where
@@ -127,7 +129,7 @@ the same partition as the current row.
127-}
129-}
128partitionBy
130partitionBy
129 :: SOP.SListI bys
131 :: SOP.SListI bys
130− => NP (Expression outer commons grp schemas params from) bys
132+ => NP (Expression outer commons grp schemas params from) bys -- ^ partitions
131 -> WindowDefinition outer commons grp schemas params from
133 -> WindowDefinition outer commons grp schemas params from
132partitionBy bys = WindowDefinition bys []
134partitionBy bys = WindowDefinition bys []
133
135
@@ -193,6 +195,7 @@ unsafeWindowFunctionN fun xs = UnsafeWindowFunction $ fun <>
193 parenthesized (renderCommaSeparated renderSQL xs)
195 parenthesized (renderCommaSeparated renderSQL xs)
194
196
195{- | rank of the current row with gaps; same as `rowNumber` of its first peer
197{- | rank of the current row with gaps; same as `rowNumber` of its first peer
198+
196>>> printSQL rank
199>>> printSQL rank
197rank()
200rank()
198-}
201-}
@@ -200,6 +203,7 @@ rank :: WinFun0 ('NotNull 'PGint8)
200rank = UnsafeWindowFunction "rank()"
203rank = UnsafeWindowFunction "rank()"
201
204
202{- | number of the current row within its partition, counting from 1
205{- | number of the current row within its partition, counting from 1
206+
203>>> printSQL rowNumber
207>>> printSQL rowNumber
204row_number()
208row_number()
205-}
209-}
@@ -207,6 +211,7 @@ rowNumber :: WinFun0 ('NotNull 'PGint8)
207rowNumber = UnsafeWindowFunction "row_number()"
211rowNumber = UnsafeWindowFunction "row_number()"
208
212
209{- | rank of the current row without gaps; this function counts peer groups
213{- | rank of the current row without gaps; this function counts peer groups
214+
210>>> printSQL denseRank
215>>> printSQL denseRank
211dense_rank()
216dense_rank()
212-}
217-}
@@ -214,6 +219,7 @@ denseRank :: WinFun0 ('NotNull 'PGint8)
214denseRank = UnsafeWindowFunction "dense_rank()"
219denseRank = UnsafeWindowFunction "dense_rank()"
215
220
216{- | relative rank of the current row: (rank - 1) / (total partition rows - 1)
221{- | relative rank of the current row: (rank - 1) / (total partition rows - 1)
222+
217>>> printSQL percentRank
223>>> printSQL percentRank
218percent_rank()
224percent_rank()
219-}
225-}
@@ -222,6 +228,7 @@ percentRank = UnsafeWindowFunction "percent_rank()"
222
228
223{- | cumulative distribution: (number of partition rows
229{- | cumulative distribution: (number of partition rows
224preceding or peer with current row) / total partition rows
230preceding or peer with current row) / total partition rows
231+
225>>> printSQL cumeDist
232>>> printSQL cumeDist
226cume_dist()
233cume_dist()
227-}
234-}
@@ -230,6 +237,9 @@ cumeDist = UnsafeWindowFunction "cume_dist()"
230
237
231{- | integer ranging from 1 to the argument value,
238{- | integer ranging from 1 to the argument value,
232dividing the partition as equally as possible
239dividing the partition as equally as possible
240+
241+>>> printSQL $ ntile 5
242+ntile(5)
233-}
243-}
234ntile :: WinFun1 ('NotNull 'PGint4) ('NotNull 'PGint4)
244ntile :: WinFun1 ('NotNull 'PGint4) ('NotNull 'PGint4)
235ntile = unsafeWindowFunction1 "ntile"
245ntile = unsafeWindowFunction1 "ntile"