on dev help sign in
jsonAgg & jsonbAgg
commit56e5e4767a9822bc544883b3ba617858e50851a7 authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateWed 20 Feb 2019, 11:04 (8 years ago) parent3d6ddf8
1 file changed+21−7
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+21−7
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+21−7
@@ -1427,7 +1427,7 @@ class Aggregate expr1 expr2 aggr
14271427 --
14281428 -- >>> :{
14291429 -- let
1430− -- expression :: Expression (Grouped bys) commons schemas params from ('NotNull 'PGint8)
1430+ -- expression :: Expression outer ('Grouped bys) commons schemas params from ('NotNull 'PGint8)
14311431 -- expression = countStar
14321432 -- in printSQL expression
14331433 -- :}
@@ -1436,7 +1436,7 @@ class Aggregate expr1 expr2 aggr
14361436
14371437 -- | >>> :{
14381438 -- 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)
14401440 -- expression = count (All #col)
14411441 -- in printSQL expression
14421442 -- :}
@@ -1463,6 +1463,16 @@ class Aggregate expr1 expr2 aggr
14631463 :: expr1 ty
14641464 -> aggr ('NotNull ('PGvararray ty))
14651465
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+
14661476 -- | >>> :{
14671477 -- let
14681478 -- expression :: Expression outer ('Grouped bys) commons schemas params '[tab ::: '["col" ::: nullity 'PGint4]] (nullity 'PGint4)
@@ -1503,7 +1513,7 @@ class Aggregate expr1 expr2 aggr
15031513
15041514 -- | >>> :{
15051515 -- 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)
15071517 -- expression = boolOr (All #col)
15081518 -- in printSQL expression
15091519 -- :}
@@ -1548,7 +1558,7 @@ class Aggregate expr1 expr2 aggr
15481558 {- | correlation coefficient
15491559 >>> :{
15501560 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)
15521562 expression = corr (All (#y :*: #x))
15531563 in printSQL expression
15541564 :}
@@ -1561,7 +1571,7 @@ class Aggregate expr1 expr2 aggr
15611571 {- | population covariance
15621572 >>> :{
15631573 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)
15651575 expression = covarPop (All (#y :*: #x))
15661576 in printSQL expression
15671577 :}
@@ -1587,7 +1597,7 @@ class Aggregate expr1 expr2 aggr
15871597 {- | average of the independent variable (sum(X)/N)
15881598 >>> :{
15891599 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)
15911601 expression = regrAvgX (All (#y :*: #x))
15921602 in printSQL expression
15931603 :}
@@ -1626,7 +1636,7 @@ class Aggregate expr1 expr2 aggr
16261636 {- | y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs
16271637 >>> :{
16281638 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)
16301640 expression = regrIntercept (All (#y :*: #x))
16311641 in printSQL expression
16321642 :}
@@ -1725,6 +1735,8 @@ instance Aggregate
17251735 count = unsafeAggregate1 "count"
17261736 sum_ = unsafeAggregate1 "sum"
17271737 arrayAgg = unsafeAggregate1 "array_agg"
1738+ jsonAgg = unsafeAggregate1 "json_agg"
1739+ jsonbAgg = unsafeAggregate1 "jsonb_agg"
17281740 bitAnd = unsafeAggregate1 "bit_and"
17291741 bitOr = unsafeAggregate1 "bit_or"
17301742 boolAnd = unsafeAggregate1 "bool_and"
@@ -1759,6 +1771,8 @@ instance Aggregate
17591771 count = unsafeWindowFunction1 "count"
17601772 sum_ = unsafeWindowFunction1 "sum"
17611773 arrayAgg = unsafeWindowFunction1 "array_agg"
1774+ jsonAgg = unsafeWindowFunction1 "json_agg"
1775+ jsonbAgg = unsafeWindowFunction1 "jsonb_agg"
17621776 bitAnd = unsafeWindowFunction1 "bit_and"
17631777 bitOr = unsafeWindowFunction1 "bit_or"
17641778 boolAnd = unsafeWindowFunction1 "bool_and"