@@ -152,6 +152,12 @@ module Squeal.PostgreSQL.Expression
152 , denseRank
152 , denseRank
153 , percentRank
153 , percentRank
154 , cumeDist
154 , cumeDist
155 -- * Sorting
161 -- * Sorting
156 , SortExpression (..)
162 , SortExpression (..)
157 , OrderBy (..)
163 , OrderBy (..)
@@ -1921,3 +1927,79 @@ cume_dist()
1922cumeDist :: WindowFunction commons schemas from grp params ('NotNull 'PGfloat8)
1928cumeDist :: WindowFunction commons schemas from grp params ('NotNull 'PGfloat8)
1923cumeDist = UnsafeWindowFunction "cume_dist()"
1929cumeDist = UnsafeWindowFunction "cume_dist()"
1931+{- | integer ranging from 1 to the argument value,
1932+dividing the partition as equally as possible
1935+ :: Expression commons schemas from grp params ('NotNull 'PGint4)
1937+ -> WindowFunction commons schemas from grp params ('NotNull 'PGint4)
1938+ntile numBuckets = UnsafeWindowFunction $ "ntile"
1939+ <> parenthesized (renderSQL numBuckets)
1941+{- | returns value evaluated at the row that is offset rows before the current
1942+row within the partition; if there is no such row, instead return default
1943+(which must be of the same type as value). Both offset and default are
1944+evaluated with respect to the current row.
1947+ :: Expression commons schemas from grp params ty
1949+ -> Expression commons schemas from grp params ('NotNull 'PGint4)
1951+ -> Expression commons schemas from grp params ty
1953+ -> WindowFunction commons schemas from grp params ty
1954+lag value offset def = UnsafeWindowFunction $ "lag"
1956+ (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
1958+{- | returns value evaluated at the row that is offset rows after the current
1959+row within the partition; if there is no such row, instead return default
1960+(which must be of the same type as value). Both offset and default are
1961+evaluated with respect to the current row.
1964+ :: Expression commons schemas from grp params ty
1966+ -> Expression commons schemas from grp params ('NotNull 'PGint4)
1968+ -> Expression commons schemas from grp params ty
1970+ -> WindowFunction commons schemas from grp params ty
1971+lead value offset def = UnsafeWindowFunction $ "lag"
1973+ (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
1975+{- | returns value evaluated at the row that is the
1976+first row of the window frame
1979+ :: Expression commons schemas from grp params ty
1981+ -> WindowFunction commons schemas from grp params ty
1982+firstValue value = UnsafeWindowFunction $ "first_value"
1983+ <> parenthesized (renderSQL value)
1985+{- | returns value evaluated at the row that is the
1986+last row of the window frame
1989+ :: Expression commons schemas from grp params ty
1991+ -> WindowFunction commons schemas from grp params ty
1992+lastValue value = UnsafeWindowFunction $ "last_value"
1993+ <> parenthesized (renderSQL value)
1995+{- | returns value evaluated at the row that is the nth
1996+row of the window frame (counting from 1); null if no such row
1999+ :: Expression commons schemas from grp params (nullity ty)
2001+ -> Expression commons schemas from grp params ('NotNull 'PGint4)
2003+ -> WindowFunction commons schemas from grp params ('Null ty)
2004+nthValue value nth = UnsafeWindowFunction $ "nth_value"
2005+ <> parenthesized (commaSeparated [renderSQL value, renderSQL nth])