on master help sign in
Add a warning that sum adds a cast and can overflow
1926f58Ollie Charles
src/Rel8/Expr/Aggregate.hs+5−1
@@ -116,7 +116,11 @@ min = unsafeMakeAggregate toPrimExpr fromPrimExpr $
116 , distinction = Opaleye.AggrAll
116 , distinction = Opaleye.AggrAll
117 }
117 }
118
118
119−-- | Corresponds to @sum@.
119+-- | Corresponds to @sum@. Note that in SQL, @sum@ is type changing - for
120+-- example the @sum@ of @integer@ returns a @bigint@. Rel8 doesn't support
121+-- this, and will add explicit cast back to the original input type. This can
122+-- lead to overflows, and if you anticipate very large sums, you should upcast
123+-- your input.
120sum :: Sql DBSum a => Expr a -> Aggregate (Expr a)
124sum :: Sql DBSum a => Expr a -> Aggregate (Expr a)
121sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
125sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
122 Just Aggregator
126 Just Aggregator