min

Function min 

Source
pub fn min<ST: SqlOrdAggregate, expr>(
    expr: expr,
) -> min<ST, <expr as AsExpression<ST>>::Expression>
where expr: AsExpression<ST>,
Expand description

Represents a SQL MIN function. This function can only take types which are ordered.

§Window Function Usage

This function can be used as window function. See WindowExpressionMethods for details

§Aggregate Function Expression

This function can be used as aggregate expression. See AggregateExpressionMethods for details.

§Examples

§Normal function usage

assert_eq!(Ok(Some(4)), animals.select(min(legs)).first(connection));

§Window function

let res = animals
    .select((name, min(legs).partition_by(id)))
    .load::<(Option<String>, Option<i32>)>(connection);

assert_eq!(
    Ok(vec![(Some("Jack".into()), Some(4)), (None, Some(8))]),
    res
);

§Aggregate function expression

assert_eq!(
    Ok(Some(8)),
    animals
        .select(min(legs).aggregate_filter(legs.gt(4)))
        .first(connection)
);