-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Milestone
Description
Please correct me if I'm misled, but it seems that Diesel currently doesn't support GROUP BY statements. #89 sounds like we can already call .group_by as of today, but there's actually no such method. Am I correct?
Another issue I encountered was that I can't write donate::table.select((donate::name, diesel::expression::sum(donate::amount))). It type-errors:
src/eventer.rs:189:31: 189:37 error: the trait `diesel::expression::SelectableExpression<eventer::donate::table, _>` is not implemented for the type `(eventer::donate::columns::name, diesel::expression::functions::aggregate_folding::Sum<eventer::donate::columns::amount>)` [E0277]
So I ended up working around the two issues above by using sql, such like:
donate::table.select((donate::name, sql::<Text>("sum(amount) AS sum")))
.filter(sql("TRUE GROUP BY name"))
.order(sql::<Text>("sum").desc())
.load(&*db).unwrap();One more thing: I had to use sql::<Text>("sum") because without ::<Text>, type inference fails. Though Text isn't exactly sane in this case, I'd say...
Any ideas? Thanks in advance for your help!
Reactions are currently unavailable