Function diesel::dsl::avg

source · []
pub fn avg<ST: Foldable, expr>(
    expr: expr
) -> avg<ST, <expr as AsExpression<ST>>::Expression> where
    expr: AsExpression<ST>, 
Expand description

Represents a SQL AVG function. This function can only take types which are Foldable.

Examples

diesel::insert_into(numbers)
    .values(&vec![number.eq(1), number.eq(2)])
    .execute(&conn)?;
let average = numbers.select(avg(number)).get_result(&conn)?;
let expected = "1.5".parse::<BigDecimal>().unwrap();
assert_eq!(Some(expected), average);