on dev help sign in
agg stuff
bf722d1Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+58−41
@@ -1461,7 +1461,7 @@ class Aggregate expr1 expr2 aggr
1461
1461
1462 -- | >>> :{
1462 -- | >>> :{
1463 -- let
1463 -- let
1464− -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('Null 'PGnumeric)
1464+ -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: 'Null 'PGnumeric]] ('NotNull 'PGnumeric)
1465 -- expression = sum_ (Distinct #col)
1465 -- expression = sum_ (Distinct #col)
1466 -- in printSQL expression
1466 -- in printSQL expression
1467 -- :}
1467 -- :}
@@ -1469,7 +1469,7 @@ class Aggregate expr1 expr2 aggr
1469 sum_
1469 sum_
1470 :: ty `In` PGNum
1470 :: ty `In` PGNum
1471 => expr1 (nullity ty)
1471 => expr1 (nullity ty)
1472− -> aggr ('Null ty)
1472+ -> aggr ('NotNull ty)
1473
1473
1474 -- | input values, including nulls, concatenated into an array
1474 -- | input values, including nulls, concatenated into an array
1475 arrayAgg
1475 arrayAgg
@@ -1486,71 +1486,88 @@ class Aggregate expr1 expr2 aggr
1486 :: expr1 ty
1486 :: expr1 ty
1487 -> aggr ('Null 'PGjsonb)
1487 -> aggr ('Null 'PGjsonb)
1488
1488
1489+ {- |
1490+ the bitwise AND of all non-null input values, or null if none
1489− -- | >>> :{
1491+ >>> :{
1490− -- let
1492+ let
1491− -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1493+ expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] ('Null 'PGint4)
1492− -- expression = bitAnd (Distinct #col)
1494+ expression = bitAnd (Distinct #col)
1493− -- in printSQL expression
1495+ in printSQL expression
1494− -- :}
1496+ :}
1495− -- bit_and(DISTINCT "col")
1497+ bit_and(DISTINCT "col")
1498+ -}
1496 bitAnd
1499 bitAnd
1497 :: int `In` PGIntegral
1500 :: int `In` PGIntegral
1498 => expr1 (nullity int)
1501 => expr1 (nullity int)
1499 -- ^ what to aggregate
1502 -- ^ what to aggregate
1500 -> aggr ('Null int)
1503 -> aggr ('Null int)
1501
1504
1505+ {- |
1506+ the bitwise OR of all non-null input values, or null if none
1507+
1502− -- | >>> :{
1508+ >>> :{
1503− -- let
1509+ let
1504− -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1510+ expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] ('Null 'PGint4)
1505− -- expression = bitOr (All #col)
1511+ expression = bitOr (All #col)
1506− -- in printSQL expression
1512+ in printSQL expression
1507− -- :}
1513+ :}
1508− -- bit_or(ALL "col")
1514+ bit_or(ALL "col")
1515+ -}
1509 bitOr
1516 bitOr
1510 :: int `In` PGIntegral
1517 :: int `In` PGIntegral
1511 => expr1 (nullity int)
1518 => expr1 (nullity int)
1512 -- ^ what to aggregate
1519 -- ^ what to aggregate
1513 -> aggr ('Null int)
1520 -> aggr ('Null int)
1514
1521
1522+ {- |
1523+ true if all input values are true, otherwise false
1524+
1515− -- | >>> :{
1525+ >>> :{
1516− -- let
1526+ let
1517− -- winFun :: WindowFunction '[] 'Ungrouped commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1527+ winFun :: WindowFunction '[] 'Ungrouped commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] ('Null 'PGbool)
1518− -- winFun = boolAnd #col
1528+ winFun = boolAnd #col
1519− -- in printSQL winFun
1529+ in printSQL winFun
1520− -- :}
1530+ :}
1521− -- bool_and("col")
1531+ bool_and("col")
1532+ -}
1522 boolAnd
1533 boolAnd
1523 :: expr1 (nullity 'PGbool)
1534 :: expr1 (nullity 'PGbool)
1524 -- ^ what to aggregate
1535 -- ^ what to aggregate
1525 -> aggr ('Null 'PGbool)
1536 -> aggr ('Null 'PGbool)
1526
1537
1538+ {- |
1539+ true if at least one input value is true, otherwise false
1540+
1527− -- | >>> :{
1541+ >>> :{
1528− -- let
1542+ let
1529− -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1543+ expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1530− -- expression = boolOr (All #col)
1544+ expression = boolOr (All #col)
1531− -- in printSQL expression
1545+ in printSQL expression
1532− -- :}
1546+ :}
1533− -- bool_or(ALL "col")
1547+ bool_or(ALL "col")
1548+ -}
1534 boolOr
1549 boolOr
1535 :: expr1(nullity 'PGbool)
1550 :: expr1(nullity 'PGbool)
1536 -- ^ what to aggregate
1551 -- ^ what to aggregate
1537 -> aggr ('Null 'PGbool)
1552 -> aggr ('Null 'PGbool)
1538
1553
1539− -- | synonym for `boolAnd`
1554+ {- |
1540− --
1555+ equivalent to `boolAnd`
1556+
1541− -- >>> :{
1557+ >>> :{
1542− -- let
1558+ let
1543− -- expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1559+ expression :: Expression '[] ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1544− -- expression = every (Distinct #col)
1560+ expression = every (Distinct #col)
1545− -- in printSQL expression
1561+ in printSQL expression
1546− -- :}
1562+ :}
1547− -- every(DISTINCT "col")
1563+ every(DISTINCT "col")
1564+ -}
1548 every
1565 every
1549 :: expr1 (nullity 'PGbool)
1566 :: expr1 (nullity 'PGbool)
1550 -- ^ what to aggregate
1567 -- ^ what to aggregate
1551 -> aggr ('Null 'PGbool)
1568 -> aggr ('Null 'PGbool)
1552
1569
1553− -- | maximum value of expression across all input values
1570+ {- |maximum value of expression across all input values-}
1554 max_
1571 max_
1555 :: expr1 (nullity ty)
1572 :: expr1 (nullity ty)
1556 -- ^ what to maximize
1573 -- ^ what to maximize
@@ -1562,7 +1579,7 @@ class Aggregate expr1 expr2 aggr
1562 -- ^ what to minimize
1579 -- ^ what to minimize
1563 -> aggr ('Null ty)
1580 -> aggr ('Null ty)
1564
1581
1565− -- | average aggregation
1582+ -- | the average (arithmetic mean) of all input values
1566 avg
1583 avg
1567 :: expr1 (nullity ty)
1584 :: expr1 (nullity ty)
1568 -- ^ what to average
1585 -- ^ what to average