Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up`GROUP BY` support #210
Comments
This comment has been minimized.
|
You are correct, we are missing support for For the most part, your workaround appears to be the way to go about doing this in the short term. The In the short term, I think it's fine for us to add a |
sgrif
added
enhancement
accepted
labels
Feb 13, 2016
added a commit
that referenced
this issue
Feb 13, 2016
This comment has been minimized.
|
@barosl I've pushed up 6df20de which adds a donate::table.select((donate::name, sql::<BigInteger>("sum(amount) AS sum")))
.group_by(donate::name)
.order(sql::<BigInteger>("sum").desc())
.load(&*db).unwrap();which is a little more sane. I'm not going to ship a new version for this change, as it doesn't affect the public API. That means you'll have to point at git for now, but next time I have a bug fix to use as an excuse I'll ship 0.5.2 which will include that change. This "fix" does not close this issue, nor does it constitute proper group by support, it's simply a crappy workaround that is slightly less crapy than |
This comment has been minimized.
|
Note for anybody reading this because they're looking for issues to work on: Before we can add proper support for group by, we almost certainly need to resolve #3. |
This comment has been minimized.
|
Ah, thanks for the explanation! I think I can live with The reason why I used |
This comment has been minimized.
I just pushed a better workaround. :P Still not great, but less silly at least.
|
This comment has been minimized.
Oh, I thought the added
Oops, it seems that the pasted code above is different from my production code. I actually did use |
This comment has been minimized.
Correct
Also correct |
This comment has been minimized.
|
Awesome! Thanks for the explanation. |
sgrif
referenced this issue
Mar 1, 2017
Closed
Cannot select aggregate and non-aggregate fields #772
This comment has been minimized.
Boscop
commented
Jun 8, 2018
|
Does this mean it's not possible to group by a non-fkey column? |
barosl commentedFeb 13, 2016
Please correct me if I'm misled, but it seems that Diesel currently doesn't support
GROUP BYstatements. #89 sounds like we can already call.group_byas 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:So I ended up working around the two issues above by using
sql, such like:One more thing: I had to use
sql::<Text>("sum")because without::<Text>, type inference fails. ThoughTextisn't exactly sane in this case, I'd say...Any ideas? Thanks in advance for your help!