@@ -1396,8 +1396,6 @@ aggregation
13961396class Aggregate expr1 expr2 aggr
13971397 | aggr -> expr1, aggr -> expr2 where
13981398
1399−
1400−
14011399 -- | A special aggregation that does not require an input
14021400 --
14031401 -- >>> :{
@@ -1497,13 +1495,13 @@ class Aggregate expr1 expr2 aggr
14971495 -- ^ what to aggregate
14981496 -> aggr (nullity 'PGbool)
14991497
1500− -- | maximum aggregation
1498+ -- | maximum value of expression across all input values
15011499 max_
15021500 :: expr1 (nullity ty)
15031501 -- ^ what to maximize
15041502 -> aggr (nullity ty)
15051503
1506− -- | minimum aggregation
1504+ -- | minimum value of expression across all input values
15071505 min_
15081506 :: expr1 (nullity ty)
15091507 -- ^ what to minimize
@@ -1515,31 +1513,103 @@ class Aggregate expr1 expr2 aggr
15151513 -- ^ what to average
15161514 -> aggr (nullity (PGAvg ty))
15171515
1518− -- | correlation coefficient
1516+ -- | @corr (y :*: x)@, correlation coefficient
15191517 corr
15201518 :: expr2 (nullity 'PGfloat8)
15211519 -> aggr (nullity 'PGfloat8)
15221520
1523− -- | population covariance
1521+ -- | @covarPop (y :*: x)@, population covariance
15241522 covarPop
15251523 :: expr2 (nullity 'PGfloat8)
15261524 -> aggr (nullity 'PGfloat8)
15271525
1528− -- | sample covariance
1526+ -- | @covarPop (y :*: x)@, sample covariance
15291527 covarSamp
15301528 :: expr2 (nullity 'PGfloat8)
15311529 -> aggr (nullity 'PGfloat8)
15321530
1533− -- | average of the independent variable (sum(X)/N)
1531+ -- | @regrAvgX (y :*: x)@, average of the independent variable (sum(X)/N)
15341532 regrAvgX
15351533 :: expr2 (nullity 'PGfloat8)
15361534 -> aggr (nullity 'PGfloat8)
15371535
1538− -- | average of the dependent variable (sum(Y)/N)
1536+ -- | @regrAvgY (y :*: x)@, average of the dependent variable (sum(Y)/N)
15391537 regrAvgY
15401538 :: expr2 (nullity 'PGfloat8)
15411539 -> aggr (nullity 'PGfloat8)
15421540
1541+ -- | @regrCount (y :*: x)@, number of input rows in which both expressions are nonnull
1542+ regrCount
1543+ :: expr2 (nullity 'PGfloat8)
1544+ -> aggr (nullity 'PGint8)
1545+
1546+ -- | @regrIntercept (y :*: x)@, y-intercept of the least-squares-fit linear
1547+ -- equation determined by the (X, Y) pairs
1548+ regrIntercept
1549+ :: expr2 (nullity 'PGfloat8)
1550+ -> aggr (nullity 'PGfloat8)
1551+
1552+ -- | @regrR2 (y :*: x)@, square of the correlation coefficient
1553+ regrR2
1554+ :: expr2 (nullity 'PGfloat8)
1555+ -> aggr (nullity 'PGfloat8)
1556+
1557+ -- | @regrSlope (y :*: x)@, slope of the least-squares-fit linear equation
1558+ -- determined by the (X, Y) pairs
1559+ regrSlope
1560+ :: expr2 (nullity 'PGfloat8)
1561+ -> aggr (nullity 'PGfloat8)
1562+
1563+ -- | @regrSxx (y :*: x)@, sum(X^2) - sum(X)^2/N
1564+ -- (“sum of squares” of the independent variable)
1565+ regrSxx
1566+ :: expr2 (nullity 'PGfloat8)
1567+ -> aggr (nullity 'PGfloat8)
1568+
1569+ -- | @regrSxy (y :*: x)@, sum(X*Y) - sum(X) * sum(Y)/N
1570+ -- (“sum of products” of independent times dependent variable)
1571+ regrSxy
1572+ :: expr2 (nullity 'PGfloat8)
1573+ -> aggr (nullity 'PGfloat8)
1574+
1575+ -- | @regrSyy (y :*: x)@, sum(Y^2) - sum(Y)^2/N
1576+ -- (“sum of squares” of the dependent variable)
1577+ regrSyy
1578+ :: expr2 (nullity 'PGfloat8)
1579+ -> aggr (nullity 'PGfloat8)
1580+
1581+ -- | historical alias for `stddevSamp`
1582+ stddev
1583+ :: expr1 (nullity ty)
1584+ -> aggr (nullity (PGAvg ty))
1585+
1586+ -- | population standard deviation of the input values
1587+ stddevPop
1588+ :: expr1 (nullity ty)
1589+ -> aggr (nullity (PGAvg ty))
1590+
1591+ -- | sample standard deviation of the input values
1592+ stddevSamp
1593+ :: expr1 (nullity ty)
1594+ -> aggr (nullity (PGAvg ty))
1595+
1596+ -- | historical alias for `varSamp`
1597+ variance
1598+ :: expr1 (nullity ty)
1599+ -> aggr (nullity (PGAvg ty))
1600+
1601+ -- | population variance of the input values
1602+ -- (square of the population standard deviation)
1603+ varPop
1604+ :: expr1 (nullity ty)
1605+ -> aggr (nullity (PGAvg ty))
1606+
1607+ -- | sample variance of the input values
1608+ -- (square of the sample standard deviation)
1609+ varSamp
1610+ :: expr1 (nullity ty)
1611+ -> aggr (nullity (PGAvg ty))
1612+
15431613data Distinction expr ty
15441614 = All (expr ty)
15451615 | Distinct (expr ty)
@@ -1580,6 +1650,19 @@ instance Aggregate
15801650 covarSamp = unsafeAggregate2 "covar_samp"
15811651 regrAvgX = unsafeAggregate2 "regr_avgx"
15821652 regrAvgY = unsafeAggregate2 "regr_avgy"
1653+ regrCount = unsafeAggregate2 "regr_count"
1654+ regrIntercept = unsafeAggregate2 "regr_intercept"
1655+ regrR2 = unsafeAggregate2 "regr_r2"
1656+ regrSlope = unsafeAggregate2 "regr_slope"
1657+ regrSxx = unsafeAggregate2 "regr_sxx"
1658+ regrSxy = unsafeAggregate2 "regr_sxy"
1659+ regrSyy = unsafeAggregate2 "regr_syy"
1660+ stddev = unsafeAggregate1 "stddev"
1661+ stddevPop = unsafeAggregate1 "stddev_pop"
1662+ stddevSamp = unsafeAggregate1 "stddev_samp"
1663+ variance = unsafeAggregate1 "variance"
1664+ varPop = unsafeAggregate1 "var_pop"
1665+ varSamp = unsafeAggregate1 "var_samp"
15831666instance Aggregate
15841667 (Expression grp commons schemas params from)
15851668 (Expression grp commons schemas params from GHC.:*: Expression grp commons schemas params from)
@@ -1600,6 +1683,19 @@ instance Aggregate
16001683 covarSamp = unsafeWindowFunction2 "covar_samp"
16011684 regrAvgX = unsafeWindowFunction2 "regr_avgx"
16021685 regrAvgY = unsafeWindowFunction2 "regr_avgy"
1686+ regrCount = unsafeWindowFunction2 "regr_count"
1687+ regrIntercept = unsafeWindowFunction2 "regr_intercept"
1688+ regrR2 = unsafeWindowFunction2 "regr_r2"
1689+ regrSlope = unsafeWindowFunction2 "regr_slope"
1690+ regrSxx = unsafeWindowFunction2 "regr_sxx"
1691+ regrSxy = unsafeWindowFunction2 "regr_sxy"
1692+ regrSyy = unsafeWindowFunction2 "regr_syy"
1693+ stddev = unsafeWindowFunction1 "stddev"
1694+ stddevPop = unsafeWindowFunction1 "stddev_pop"
1695+ stddevSamp = unsafeWindowFunction1 "stddev_samp"
1696+ variance = unsafeWindowFunction1 "variance"
1697+ varPop = unsafeWindowFunction1 "var_pop"
1698+ varSamp = unsafeWindowFunction1 "var_samp"
16031699
16041700-- | escape hatch to define aggregate functions
16051701unsafeAggregate1