on master help sign in
Add a warning that sum adds a cast and can overflow
commit1926f582766e358aad81750450f9221055d96686 authorOllie Charles <ollie@ocharles.org.uk> dateWed 24 Mar 2021, 12:05 (6 years ago) parent3c86905
1 file changed+5−1
src/Rel8/Expr/Aggregate.hs+5−1
src/Rel8/Expr/Aggregate.hs+5−1
@@ -116,7 +116,11 @@ min = unsafeMakeAggregate toPrimExpr fromPrimExpr $
116116 , distinction = Opaleye.AggrAll
117117 }
118118
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.
120124sum :: Sql DBSum a => Expr a -> Aggregate (Expr a)
121125sum = unsafeMakeAggregate toPrimExpr (castExpr . fromPrimExpr) $
122126 Just Aggregator