@@ -58,6 +58,7 @@ module Squeal.PostgreSQL.Expression
5858 -- ** Functions
5959 , unsafeBinaryOp
6060 , unsafeUnaryOpL
61+ , unsafeUnaryOpR
6162 , unsafeFunction
6263 , unsafeVariadicFunction
6364 , atan2_
@@ -241,7 +242,6 @@ module Squeal.PostgreSQL.Expression
241242 -- * Re-export
242243 , (&)
243244 , NP (..)
244− , (:*:) (..)
245245 , K (..)
246246 ) where
247247
@@ -250,12 +250,12 @@ import Control.DeepSeq
250250import Data.ByteString (ByteString)
251251import Data.ByteString.Lazy (toStrict)
252252import Data.Function ((&))
253+import Data.Kind
253254import Data.Semigroup hiding (All)
254255import qualified Data.Aeson as JSON
255256import Data.String
256257import Data.Word
257258import Generics.SOP hiding (All, from)
258−import GHC.Generics ((:*:) (..))
259259import GHC.OverloadedLabels
260260import GHC.TypeLits
261261import Numeric
@@ -1552,13 +1552,31 @@ tsHeadline = unsafeFunctionHet "ts_headline"
15521552aggregation
15531553-----------------------------------------}
15541554
1555+type AggrFun x y
1556+ = forall outer bys commons schemas params from
1557+ . Distinction (Expression outer 'Ungrouped commons schemas params from) x
1558+ -- ^ input
1559+ -> Expression outer ('Grouped bys) commons schemas params from y
1560+ -- ^ output
1561+
1562+type AggrHet xs y
1563+ = forall outer bys commons schemas params from
1564+ . Distinction (NP (Expression outer 'Ungrouped commons schemas params from)) xs
1565+ -- ^ inputs
1566+ -> Expression outer ('Grouped bys) commons schemas params from y
1567+ -- ^ output
1568+
1569+unsafeAggregateHet :: SOP.SListI xs => ByteString -> AggrHet xs y
1570+unsafeAggregateHet fun xs = UnsafeExpression $ mconcat
1571+ [fun, "(", renderSQL xs, ")"]
1572+
15551573{- |
15561574`Aggregate` functions compute a single result from a set of input values.
15571575`Aggregate` functions can be used as `GroupedBy` `Expression`s as well
15581576as `WindowFunction`s.
15591577-}
1560−class Aggregate expr1 expr2 aggr
1561− | aggr -> expr1, aggr -> expr2 where
1578+class Aggregate expr1 exprHet aggr
1579+ | aggr -> expr1, aggr -> exprHet where
15621580
15631581 -- | A special aggregation that does not require an input
15641582 --
@@ -1671,7 +1689,7 @@ class Aggregate expr1 expr2 aggr
16711689 bool_or(ALL "col")
16721690 -}
16731691 boolOr
1674− :: expr1(null 'PGbool)
1692+ :: expr1 (null 'PGbool)
16751693 -- ^ what to aggregate
16761694 -> aggr ('Null 'PGbool)
16771695
@@ -1713,120 +1731,120 @@ class Aggregate expr1 expr2 aggr
17131731 >>> :{
17141732 let
17151733 expression :: Expression '[] ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1716− expression = corr (All (#y :*: #x))
1734+ expression = corr (All (#y *: #x))
17171735 in printSQL expression
17181736 :}
17191737 corr(ALL "y", "x")
17201738 -}
17211739 corr
1722− :: expr2 (null 'PGfloat8)
1740+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
17231741 -> aggr ('Null 'PGfloat8)
17241742
17251743 {- | population covariance
17261744 >>> :{
17271745 let
17281746 expression :: Expression '[] ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1729− expression = covarPop (All (#y :*: #x))
1747+ expression = covarPop (All (#y *: #x))
17301748 in printSQL expression
17311749 :}
17321750 covar_pop(ALL "y", "x")
17331751 -}
17341752 covarPop
1735− :: expr2 (null 'PGfloat8)
1753+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
17361754 -> aggr ('Null 'PGfloat8)
17371755
17381756 {- | sample covariance
17391757 >>> :{
17401758 let
17411759 winFun :: WindowFunction '[] 'Ungrouped c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1742− winFun = covarSamp (#y :*: #x)
1760+ winFun = covarSamp (#y *: #x)
17431761 in printSQL winFun
17441762 :}
17451763 covar_samp("y", "x")
17461764 -}
17471765 covarSamp
1748− :: expr2 (null 'PGfloat8)
1766+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
17491767 -> aggr ('Null 'PGfloat8)
17501768
17511769 {- | average of the independent variable (sum(X)/N)
17521770 >>> :{
17531771 let
17541772 expression :: Expression '[] ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1755− expression = regrAvgX (All (#y :*: #x))
1773+ expression = regrAvgX (All (#y *: #x))
17561774 in printSQL expression
17571775 :}
17581776 regr_avgx(ALL "y", "x")
17591777 -}
17601778 regrAvgX
1761− :: expr2 (null 'PGfloat8)
1779+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
17621780 -> aggr ('Null 'PGfloat8)
17631781
17641782 {- | average of the dependent variable (sum(Y)/N)
17651783 >>> :{
17661784 let
17671785 winFun :: WindowFunction '[] 'Ungrouped c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1768− winFun = regrAvgY (#y :*: #x)
1786+ winFun = regrAvgY (#y *: #x)
17691787 in printSQL winFun
17701788 :}
17711789 regr_avgy("y", "x")
17721790 -}
17731791 regrAvgY
1774− :: expr2 (null 'PGfloat8)
1792+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
17751793 -> aggr ('Null 'PGfloat8)
17761794
17771795 {- | number of input rows in which both expressions are nonnull
17781796 >>> :{
17791797 let
17801798 winFun :: WindowFunction '[] 'Ungrouped c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGint8)
1781− winFun = regrCount (#y :*: #x)
1799+ winFun = regrCount (#y *: #x)
17821800 in printSQL winFun
17831801 :}
17841802 regr_count("y", "x")
17851803 -}
17861804 regrCount
1787− :: expr2 (null 'PGfloat8)
1805+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
17881806 -> aggr ('Null 'PGint8)
17891807
17901808 {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
17911809 >>> :{
17921810 let
17931811 expression :: Expression '[] ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('Null 'PGfloat8)
1794− expression = regrIntercept (All (#y :*: #x))
1812+ expression = regrIntercept (All (#y *: #x))
17951813 in printSQL expression
17961814 :}
17971815 regr_intercept(ALL "y", "x")
17981816 -}
17991817 regrIntercept
1800− :: expr2 (null 'PGfloat8)
1818+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
18011819 -> aggr ('Null 'PGfloat8)
18021820
18031821 -- | @regr_r2(Y, X)@, square of the correlation coefficient
18041822 regrR2
1805− :: expr2 (null 'PGfloat8)
1823+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
18061824 -> aggr ('Null 'PGfloat8)
18071825
18081826 -- | @regr_slope(Y, X)@, slope of the least-squares-fit linear equation
18091827 -- determined by the (X, Y) pairs
18101828 regrSlope
1811− :: expr2 (null 'PGfloat8)
1829+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
18121830 -> aggr ('Null 'PGfloat8)
18131831
18141832 -- | @regr_sxx(Y, X)@, sum(X^2) - sum(X)^2/N
18151833 -- (“sum of squares” of the independent variable)
18161834 regrSxx
1817− :: expr2 (null 'PGfloat8)
1835+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
18181836 -> aggr ('Null 'PGfloat8)
18191837
18201838 -- | @regr_sxy(Y, X)@, sum(X*Y) - sum(X) * sum(Y)/N
18211839 -- (“sum of products” of independent times dependent variable)
18221840 regrSxy
1823− :: expr2 (null 'PGfloat8)
1841+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
18241842 -> aggr ('Null 'PGfloat8)
18251843
18261844 -- | @regr_syy(Y, X)@, sum(Y^2) - sum(Y)^2/N
18271845 -- (“sum of squares” of the dependent variable)
18281846 regrSyy
1829− :: expr2 (null 'PGfloat8)
1847+ :: exprHet '[null 'PGfloat8, null 'PGfloat8]
18301848 -> aggr ('Null 'PGfloat8)
18311849
18321850 -- | historical alias for `stddevSamp`
@@ -1867,7 +1885,7 @@ class Aggregate expr1 expr2 aggr
18671885`Distinct` invokes the aggregate once for each distinct value of the expression
18681886(or distinct set of values, for multiple expressions) found in the input
18691887-}
1870−data Distinction expr ty
1888+data Distinction (expr :: kind -> Type) (ty :: kind)
18711889 = All (expr ty)
18721890 | Distinct (expr ty)
18731891 deriving (GHC.Generic,Show,Eq,Ord)
@@ -1876,20 +1894,15 @@ instance RenderSQL (Distinction (Expression outer grp commons schemas params fro
18761894 renderSQL = \case
18771895 All x -> "ALL" <+> renderSQL x
18781896 Distinct x -> "DISTINCT" <+> renderSQL x
1879−instance RenderSQL
1880− (Distinction
1881− ( Expression outer grp commons schemas params from
1882− :*:
1883− Expression outer grp commons schemas params from) xty ) where
1884− renderSQL = \case
1885− All (x :*: x') ->
1886− "ALL" <+> renderSQL x <> ", " <> renderSQL x'
1887− Distinct (x :*: x') ->
1888− "DISTINCT" <+> renderSQL x <> ", " <> renderSQL x'
1897+instance SOP.SListI tys => RenderSQL
1898+ (Distinction (NP (Expression outer grp commons schemas params from)) tys) where
1899+ renderSQL = \case
1900+ All xs -> "ALL" <+> renderCommaSeparated renderSQL xs
1901+ Distinct xs -> "DISTINCT" <+> renderCommaSeparated renderSQL xs
18891902
18901903instance Aggregate
18911904 (Distinction (Expression outer 'Ungrouped commons schemas params from))
1892− (Distinction (Expression outer 'Ungrouped commons schemas params from :*: Expression outer 'Ungrouped commons schemas params from))
1905+ (Distinction (NP (Expression outer 'Ungrouped commons schemas params from)))
18931906 (Expression outer ('Grouped bys) commons schemas params from) where
18941907 countStar = UnsafeExpression "count(*)"
18951908 count = unsafeAggregate1 "count"
@@ -1905,18 +1918,18 @@ instance Aggregate
19051918 max_ = unsafeAggregate1 "max"
19061919 min_ = unsafeAggregate1 "min"
19071920 avg = unsafeAggregate1 "avg"
1908− corr = unsafeAggregate2 "corr"
1909− covarPop = unsafeAggregate2 "covar_pop"
1910− covarSamp = unsafeAggregate2 "covar_samp"
1911− regrAvgX = unsafeAggregate2 "regr_avgx"
1912− regrAvgY = unsafeAggregate2 "regr_avgy"
1913− regrCount = unsafeAggregate2 "regr_count"
1914− regrIntercept = unsafeAggregate2 "regr_intercept"
1915− regrR2 = unsafeAggregate2 "regr_r2"
1916− regrSlope = unsafeAggregate2 "regr_slope"
1917− regrSxx = unsafeAggregate2 "regr_sxx"
1918− regrSxy = unsafeAggregate2 "regr_sxy"
1919− regrSyy = unsafeAggregate2 "regr_syy"
1921+ corr = unsafeAggregateHet "corr"
1922+ covarPop = unsafeAggregateHet "covar_pop"
1923+ covarSamp = unsafeAggregateHet "covar_samp"
1924+ regrAvgX = unsafeAggregateHet "regr_avgx"
1925+ regrAvgY = unsafeAggregateHet "regr_avgy"
1926+ regrCount = unsafeAggregateHet "regr_count"
1927+ regrIntercept = unsafeAggregateHet "regr_intercept"
1928+ regrR2 = unsafeAggregateHet "regr_r2"
1929+ regrSlope = unsafeAggregateHet "regr_slope"
1930+ regrSxx = unsafeAggregateHet "regr_sxx"
1931+ regrSxy = unsafeAggregateHet "regr_sxy"
1932+ regrSyy = unsafeAggregateHet "regr_syy"
19201933 stddev = unsafeAggregate1 "stddev"
19211934 stddevPop = unsafeAggregate1 "stddev_pop"
19221935 stddevSamp = unsafeAggregate1 "stddev_samp"
@@ -1925,7 +1938,7 @@ instance Aggregate
19251938 varSamp = unsafeAggregate1 "var_samp"
19261939instance Aggregate
19271940 (Expression outer grp commons schemas params from)
1928− (Expression outer grp commons schemas params from :*: Expression outer grp commons schemas params from)
1941+ (NP (Expression outer grp commons schemas params from))
19291942 (WindowFunction outer grp commons schemas params from) where
19301943 countStar = UnsafeWindowFunction "count(*)"
19311944 count = unsafeWindowFunction1 "count"
@@ -1941,18 +1954,18 @@ instance Aggregate
19411954 max_ = unsafeWindowFunction1 "max"
19421955 min_ = unsafeWindowFunction1 "min"
19431956 avg = unsafeWindowFunction1 "avg"
1944− corr = unsafeWindowFunction2 "corr"
1945− covarPop = unsafeWindowFunction2 "covar_pop"
1946− covarSamp = unsafeWindowFunction2 "covar_samp"
1947− regrAvgX = unsafeWindowFunction2 "regr_avgx"
1948− regrAvgY = unsafeWindowFunction2 "regr_avgy"
1949− regrCount = unsafeWindowFunction2 "regr_count"
1950− regrIntercept = unsafeWindowFunction2 "regr_intercept"
1951− regrR2 = unsafeWindowFunction2 "regr_r2"
1952− regrSlope = unsafeWindowFunction2 "regr_slope"
1953− regrSxx = unsafeWindowFunction2 "regr_sxx"
1954− regrSxy = unsafeWindowFunction2 "regr_sxy"
1955− regrSyy = unsafeWindowFunction2 "regr_syy"
1957+ corr = unsafeWindowFunctionHet "corr"
1958+ covarPop = unsafeWindowFunctionHet "covar_pop"
1959+ covarSamp = unsafeWindowFunctionHet "covar_samp"
1960+ regrAvgX = unsafeWindowFunctionHet "regr_avgx"
1961+ regrAvgY = unsafeWindowFunctionHet "regr_avgy"
1962+ regrCount = unsafeWindowFunctionHet "regr_count"
1963+ regrIntercept = unsafeWindowFunctionHet "regr_intercept"
1964+ regrR2 = unsafeWindowFunctionHet "regr_r2"
1965+ regrSlope = unsafeWindowFunctionHet "regr_slope"
1966+ regrSxx = unsafeWindowFunctionHet "regr_sxx"
1967+ regrSxy = unsafeWindowFunctionHet "regr_sxy"
1968+ regrSyy = unsafeWindowFunctionHet "regr_syy"
19561969 stddev = unsafeWindowFunction1 "stddev"
19571970 stddevPop = unsafeWindowFunction1 "stddev_pop"
19581971 stddevSamp = unsafeWindowFunction1 "stddev_samp"
@@ -1963,19 +1976,10 @@ instance Aggregate
19631976-- | escape hatch to define aggregate functions
19641977unsafeAggregate1
19651978 :: ByteString -- ^ aggregate function
1966− -> Distinction (Expression outer 'Ungrouped commons schemas params from) xty
1967− -> Expression outer ('Grouped bys) commons schemas params from yty
1979+ -> AggrFun xty yty
19681980unsafeAggregate1 fun x = UnsafeExpression $ mconcat
19691981 [fun, "(", renderSQL x, ")"]
19701982
1971−-- | escape hatch to define aggregate binary functions
1972−unsafeAggregate2
1973− :: ByteString -- ^ aggregate function
1974− -> Distinction (Expression outer 'Ungrouped commons schemas params from :*: Expression outer 'Ungrouped commons schemas params from) xty
1975− -> Expression outer ('Grouped bys) commons schemas params from yty
1976−unsafeAggregate2 fun xx = UnsafeExpression $ mconcat
1977− [fun, "(", renderSQL xx, ")"]
1978−
19791983-- | A type family that calculates `PGAvg` type of a `PGType`.
19801984type family PGAvg ty where
19811985 PGAvg 'PGint2 = 'PGnumeric
@@ -2291,46 +2295,59 @@ newtype WindowFunction
22912295instance RenderSQL (WindowFunction outer grp commons schemas params from ty) where
22922296 renderSQL = renderWindowFunction
22932297
2294−unsafeWindowFunction1
2295− :: ByteString
2296− -> Expression outer grp commons schemas params from ty0
2297− -> WindowFunction outer grp commons schemas params from ty1
2298+type WinFun0 x
2299+ = forall outer grp commons schemas params from
2300+ . WindowFunction outer grp commons schemas params from x
2301+ -- ^ cannot reference aliases
2302+
2303+type WinFun1 x y
2304+ = forall outer grp commons schemas params from
2305+ . Expression outer grp commons schemas params from x
2306+ -- ^ input
2307+ -> WindowFunction outer grp commons schemas params from y
2308+ -- ^ output
2309+
2310+type WinFunHet xs y
2311+ = forall outer grp commons schemas params from
2312+ . NP (Expression outer grp commons schemas params from) xs
2313+ -- ^ inputs
2314+ -> WindowFunction outer grp commons schemas params from y
2315+ -- ^ output
2316+
2317+unsafeWindowFunction1 :: ByteString -> WinFun1 x y
22982318unsafeWindowFunction1 fun x
22992319 = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x)
23002320
2301−unsafeWindowFunction2
2302− :: ByteString
2303− -> (Expression outer grp commons schemas params from :*: Expression outer grp commons schemas params from) ty0
2304− -> WindowFunction outer grp commons schemas params from ty1
2305−unsafeWindowFunction2 fun (x :*: x')
2306− = UnsafeWindowFunction $ fun <> parenthesized (renderSQL x <> ", " <> renderSQL x')
2321+unsafeWindowFunctionHet :: SOP.SListI xs => ByteString -> WinFunHet xs y
2322+unsafeWindowFunctionHet fun xs = UnsafeWindowFunction $ fun <>
2323+ parenthesized (renderCommaSeparated renderSQL xs)
23072324
23082325{- | rank of the current row with gaps; same as `rowNumber` of its first peer
23092326>>> printSQL rank
23102327rank()
23112328-}
2312−rank :: WindowFunction outer grp commons schemas params from ('NotNull 'PGint8)
2329+rank :: WinFun0 ('NotNull 'PGint8)
23132330rank = UnsafeWindowFunction "rank()"
23142331
23152332{- | number of the current row within its partition, counting from 1
23162333>>> printSQL rowNumber
23172334row_number()
23182335-}
2319−rowNumber :: WindowFunction outer grp commons schemas params from ('NotNull 'PGint8)
2336+rowNumber :: WinFun0 ('NotNull 'PGint8)
23202337rowNumber = UnsafeWindowFunction "row_number()"
23212338
23222339{- | rank of the current row without gaps; this function counts peer groups
23232340>>> printSQL denseRank
23242341dense_rank()
23252342-}
2326−denseRank :: WindowFunction outer grp commons schemas params from ('NotNull 'PGint8)
2343+denseRank :: WinFun0 ('NotNull 'PGint8)
23272344denseRank = UnsafeWindowFunction "dense_rank()"
23282345
23292346{- | relative rank of the current row: (rank - 1) / (total partition rows - 1)
23302347>>> printSQL percentRank
23312348percent_rank()
23322349-}
2333−percentRank :: WindowFunction outer grp commons schemas params from ('NotNull 'PGfloat8)
2350+percentRank :: WinFun0 ('NotNull 'PGfloat8)
23342351percentRank = UnsafeWindowFunction "percent_rank()"
23352352
23362353{- | cumulative distribution: (number of partition rows
@@ -2338,16 +2355,13 @@ preceding or peer with current row) / total partition rows
23382355>>> printSQL cumeDist
23392356cume_dist()
23402357-}
2341−cumeDist :: WindowFunction outer grp commons schemas params from ('NotNull 'PGfloat8)
2358+cumeDist :: WinFun0 ('NotNull 'PGfloat8)
23422359cumeDist = UnsafeWindowFunction "cume_dist()"
23432360
23442361{- | integer ranging from 1 to the argument value,
23452362dividing the partition as equally as possible
23462363-}
2347−ntile
2348− :: Expression outer grp commons schemas params from ('NotNull 'PGint4)
2349− -- ^ num buckets
2350− -> WindowFunction outer grp commons schemas params from ('NotNull 'PGint4)
2364+ntile :: WinFun1 ('NotNull 'PGint4) ('NotNull 'PGint4)
23512365ntile = unsafeWindowFunction1 "ntile"
23522366
23532367{- | returns value evaluated at the row that is offset rows before the current
@@ -2355,64 +2369,34 @@ row within the partition; if there is no such row, instead return default
23552369(which must be of the same type as value). Both offset and default are
23562370evaluated with respect to the current row.
23572371-}
2358−lag
2359− :: Expression outer grp commons schemas params from ty
2360− -- ^ value
2361− -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
2362− -- ^ offset
2363− -> Expression outer grp commons schemas params from ty
2364− -- ^ default
2365− -> WindowFunction outer grp commons schemas params from ty
2366−lag value offset def = UnsafeWindowFunction $ "lag"
2367− <> parenthesized
2368− (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
2372+lag :: WinFunHet '[ty, 'NotNull 'PGint4, ty] ty
2373+lag = unsafeWindowFunctionHet "lag"
23692374
23702375{- | returns value evaluated at the row that is offset rows after the current
23712376row within the partition; if there is no such row, instead return default
23722377(which must be of the same type as value). Both offset and default are
23732378evaluated with respect to the current row.
23742379-}
2375−lead
2376− :: Expression outer grp commons schemas params from ty
2377− -- ^ value
2378− -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
2379− -- ^ offset
2380− -> Expression outer grp commons schemas params from ty
2381− -- ^ default
2382− -> WindowFunction outer grp commons schemas params from ty
2383−lead value offset def = UnsafeWindowFunction $ "lag"
2384− <> parenthesized
2385− (commaSeparated ([renderSQL value, renderSQL offset, renderSQL def]))
2380+lead :: WinFunHet '[ty, 'NotNull 'PGint4, ty] ty
2381+lead = unsafeWindowFunctionHet "lag"
23862382
23872383{- | returns value evaluated at the row that is the
23882384first row of the window frame
23892385-}
2390−firstValue
2391− :: Expression outer grp commons schemas params from ty
2392− -- ^ value
2393− -> WindowFunction outer grp commons schemas params from ty
2386+firstValue :: WinFun1 ty ty
23942387firstValue = unsafeWindowFunction1 "first_value"
23952388
23962389{- | returns value evaluated at the row that is the
23972390last row of the window frame
23982391-}
2399−lastValue
2400− :: Expression outer grp commons schemas params from ty
2401− -- ^ value
2402− -> WindowFunction outer grp commons schemas params from ty
2392+lastValue :: WinFun1 ty ty
24032393lastValue = unsafeWindowFunction1 "last_value"
24042394
24052395{- | returns value evaluated at the row that is the nth
24062396row of the window frame (counting from 1); null if no such row
24072397-}
2408−nthValue
2409− :: Expression outer grp commons schemas params from (null ty)
2410− -- ^ value
2411− -> Expression outer grp commons schemas params from ('NotNull 'PGint4)
2412− -- ^ nth
2413− -> WindowFunction outer grp commons schemas params from ('Null ty)
2414−nthValue value nth = UnsafeWindowFunction $ "nth_value"
2415− <> parenthesized (commaSeparated [renderSQL value, renderSQL nth])
2398+nthValue :: WinFunHet '[null ty, 'NotNull 'PGint4] ('Null ty)
2399+nthValue = unsafeWindowFunctionHet "nth_value"
24162400
24172401{-|
24182402Create date from year, month and day fields