on dev help sign in
jsonAgg & jsonbAgg
56e5e47Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+21−7
@@ -1427,7 +1427,7 @@ class Aggregate expr1 expr2 aggr
1427 --
1427 --
1428 -- >>> :{
1428 -- >>> :{
1429 -- let
1429 -- let
1430− -- expression :: Expression (Grouped bys) commons schemas params from ('NotNull 'PGint8)
1430+ -- expression :: Expression outer ('Grouped bys) commons schemas params from ('NotNull 'PGint8)
1431 -- expression = countStar
1431 -- expression = countStar
1432 -- in printSQL expression
1432 -- in printSQL expression
1433 -- :}
1433 -- :}
@@ -1436,7 +1436,7 @@ class Aggregate expr1 expr2 aggr
1436
1436
1437 -- | >>> :{
1437 -- | >>> :{
1438 -- let
1438 -- let
1439− -- expression :: Expression (Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1439+ -- expression :: Expression outer ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity ty]] ('NotNull 'PGint8)
1440 -- expression = count (All #col)
1440 -- expression = count (All #col)
1441 -- in printSQL expression
1441 -- in printSQL expression
1442 -- :}
1442 -- :}
@@ -1463,6 +1463,16 @@ class Aggregate expr1 expr2 aggr
1463 :: expr1 ty
1463 :: expr1 ty
1464 -> aggr ('NotNull ('PGvararray ty))
1464 -> aggr ('NotNull ('PGvararray ty))
1465
1465
1466+ -- | aggregates values as a JSON array
1467+ jsonAgg
1468+ :: expr1 ty
1469+ -> aggr ('NotNull 'PGjson)
1470+
1471+ -- | aggregates values as a JSON array
1472+ jsonbAgg
1473+ :: expr1 ty
1474+ -> aggr ('NotNull 'PGjsonb)
1475+
1466 -- | >>> :{
1476 -- | >>> :{
1467 -- let
1477 -- let
1468 -- expression :: Expression outer ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
1478 -- expression :: Expression outer ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
@@ -1503,7 +1513,7 @@ class Aggregate expr1 expr2 aggr
1503
1513
1504 -- | >>> :{
1514 -- | >>> :{
1505 -- let
1515 -- let
1506− -- expression :: Expression (Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1516+ -- expression :: Expression outer ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGbool]] (nullity 'PGbool)
1507 -- expression = boolOr (All #col)
1517 -- expression = boolOr (All #col)
1508 -- in printSQL expression
1518 -- in printSQL expression
1509 -- :}
1519 -- :}
@@ -1548,7 +1558,7 @@ class Aggregate expr1 expr2 aggr
1548 {- | correlation coefficient
1558 {- | correlation coefficient
1549 >>> :{
1559 >>> :{
1550 let
1560 let
1551− expression :: Expression ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1561+ expression :: Expression o ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1552 expression = corr (All (#y :*: #x))
1562 expression = corr (All (#y :*: #x))
1553 in printSQL expression
1563 in printSQL expression
1554 :}
1564 :}
@@ -1561,7 +1571,7 @@ class Aggregate expr1 expr2 aggr
1561 {- | population covariance
1571 {- | population covariance
1562 >>> :{
1572 >>> :{
1563 let
1573 let
1564− expression :: Expression ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1574+ expression :: Expression o ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1565 expression = covarPop (All (#y :*: #x))
1575 expression = covarPop (All (#y :*: #x))
1566 in printSQL expression
1576 in printSQL expression
1567 :}
1577 :}
@@ -1587,7 +1597,7 @@ class Aggregate expr1 expr2 aggr
1587 {- | average of the independent variable (sum(X)/N)
1597 {- | average of the independent variable (sum(X)/N)
1588 >>> :{
1598 >>> :{
1589 let
1599 let
1590− expression :: Expression ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1600+ expression :: Expression o ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1591 expression = regrAvgX (All (#y :*: #x))
1601 expression = regrAvgX (All (#y :*: #x))
1592 in printSQL expression
1602 in printSQL expression
1593 :}
1603 :}
@@ -1626,7 +1636,7 @@ class Aggregate expr1 expr2 aggr
1626 {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
1636 {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
1627 >>> :{
1637 >>> :{
1628 let
1638 let
1629− expression :: Expression ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1639+ expression :: Expression o ('Grouped g) c s p '[t ::: '["x" ::: 'NotNull 'PGfloat8, "y" ::: 'NotNull 'PGfloat8]] ('NotNull 'PGfloat8)
1630 expression = regrIntercept (All (#y :*: #x))
1640 expression = regrIntercept (All (#y :*: #x))
1631 in printSQL expression
1641 in printSQL expression
1632 :}
1642 :}
@@ -1725,6 +1735,8 @@ instance Aggregate
1725 count = unsafeAggregate1 "count"
1735 count = unsafeAggregate1 "count"
1726 sum_ = unsafeAggregate1 "sum"
1736 sum_ = unsafeAggregate1 "sum"
1727 arrayAgg = unsafeAggregate1 "array_agg"
1737 arrayAgg = unsafeAggregate1 "array_agg"
1738+ jsonAgg = unsafeAggregate1 "json_agg"
1739+ jsonbAgg = unsafeAggregate1 "jsonb_agg"
1728 bitAnd = unsafeAggregate1 "bit_and"
1740 bitAnd = unsafeAggregate1 "bit_and"
1729 bitOr = unsafeAggregate1 "bit_or"
1741 bitOr = unsafeAggregate1 "bit_or"
1730 boolAnd = unsafeAggregate1 "bool_and"
1742 boolAnd = unsafeAggregate1 "bool_and"
@@ -1759,6 +1771,8 @@ instance Aggregate
1759 count = unsafeWindowFunction1 "count"
1771 count = unsafeWindowFunction1 "count"
1760 sum_ = unsafeWindowFunction1 "sum"
1772 sum_ = unsafeWindowFunction1 "sum"
1761 arrayAgg = unsafeWindowFunction1 "array_agg"
1773 arrayAgg = unsafeWindowFunction1 "array_agg"
1774+ jsonAgg = unsafeWindowFunction1 "json_agg"
1775+ jsonbAgg = unsafeWindowFunction1 "jsonb_agg"
1762 bitAnd = unsafeWindowFunction1 "bit_and"
1776 bitAnd = unsafeWindowFunction1 "bit_and"
1763 bitOr = unsafeWindowFunction1 "bit_or"
1777 bitOr = unsafeWindowFunction1 "bit_or"
1764 boolAnd = unsafeWindowFunction1 "bool_and"
1778 boolAnd = unsafeWindowFunction1 "bool_and"