Function diesel::dsl::count_distinct

source ·
pub fn count_distinct<T, E>(expr: E) -> CountDistinct<T, E::Expression>
where T: SqlType + SingleValue, E: AsExpression<T>,
Expand description

Creates a SQL COUNT(DISTINCT ...) expression

As with most bare functions, this is not exported by default. You can import it specifically as diesel::dsl::count_distinct, or glob import diesel::dsl::*

§Examples

let unique_user_count = posts.select(count_distinct(user_id)).first(connection);
assert_eq!(Ok(2), unique_user_count);