pub fn count<T: SqlType + SingleValue, expr>(
expr: expr,
) -> count<T, <expr as AsExpression<T>>::Expression>where
expr: AsExpression<T>,
Expand description
Creates a SQL COUNT
expression
As with most bare functions, this is not exported by default. You can import
it specifically as diesel::dsl::count
, or glob import
diesel::dsl::*
§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(1), animals.select(count(name)).first(connection));
§Window function
assert_eq!(
Ok(1),
animals
.select(count(name).partition_by(id))
.first(connection)
);
§Aggregate function expression
assert_eq!(
Ok(1),
animals
.select(count(name).aggregate_distinct())
.first(connection)
);