Skip to main content

avg

Function avg 

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

AVG(expr) - calculates average of numeric values.

Requires the expression to be Numeric. Always returns Double (SQL standard behavior), nullable.

§Type Safety

// ✅ OK: Numeric column
avg(products.price);

// ❌ Compile error: Text is not Numeric
avg(users.name);