Skip to main content

sum

Function sum 

Source
pub fn sum<'a, V, E>(
    expr: E,
) -> SQLExpr<'a, V, <E::SQLType as AggregatePolicy<V::DialectMarker>>::Sum, Null, Agg, E::Sources>
where V: SQLParam + 'a, E: Expr<'a, V>, E::SQLType: AggregatePolicy<V::DialectMarker>,
Expand description

Sum of numeric values (SUM).

The argument must be numeric. The result type depends on the dialect (see AggregatePolicy): for example, PostgreSQL widens int4 to int8. The result is nullable (SUM of no rows is NULL) and an aggregate.

§Examples

assert_eq!(sum(users.age).sql(), r#"SUM ("users"."age")"#);

§Type safety

Summing a text column does not compile:

ⓘ
let wrong = sum(users.name);