You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to translate this valid SQL query to diesel dsl
CREATETABLEfoo (
uuid uuid PRIMARY KEYNOT NULL,
datetimestamp DEFAULT now() NOT NULL
);
SELECT uuid, max(date) dateFROM foo GROUP BY uuid;
What is the expected output?
Being able to mix such expressions when it's valid sql
What is the actual output?
error[E0277]: the trait bound `diesel::expression::is_aggregate::No: MixedAggregates<diesel::expression::is_aggregate::Yes>` is not satisfied
--> src/graphql/entities/user.rs:392:10
|
392 | .select((foo::uuid_1, diesel::dsl::max(foo::date)))
| ^^^^^^ the trait `MixedAggregates<diesel::expression::is_aggregate::Yes>` is not implemented for `diesel::expression::is_aggregate::No`
|
= help: the following other types implement trait `MixedAggregates<Other>`:
<diesel::expression::is_aggregate::No as MixedAggregates<diesel::expression::is_aggregate::Never>>
<diesel::expression::is_aggregate::No as MixedAggregates<diesel::expression::is_aggregate::No>>
= note: required for `(db::schema::foo::columns::uuid_1, diesel::expression::functions::aggregate_ordering::max::max<diesel::sql_types::Date, db::schema::foo::columns::date>)` to implement `ValidGrouping<()>`
= note: required for `SelectStatement<FromClause<db::schema::foo::table>>` to implement `SelectDsl<(db::schema::foo::columns::uuid_1, diesel::expression::functions::aggregate_ordering::max::max<diesel::sql_types::Date, db::schema::foo::columns::date>)>`
This is "expected" as we assume that the call to the group_by function appears before the select call. This assumption is made to have somewhat clearer error messages here (so that they point at least to the .select() call instead of only pointing at the query). So for reference the following query compiles:
That written: I just checked the documentation and it does not mention this restriction at all. We should probably have that in the documentation of .select and .group_by. So that's at least a missing/bad documentation bug.
Setup
Versions
Feature Flags
Problem Description
The following query gives some errors, mixing aggregate and non-aggregate expressions
What are you trying to accomplish?
I'm trying to translate this valid SQL query to diesel dsl
What is the expected output?
Being able to mix such expressions when it's valid sql
What is the actual output?
Are you seeing any additional errors?
No, many thanks for your hard work
Steps to reproduce
Checklist
If you are unsure if your issue is a duplicate of an existing issue please link the issue in question here
Aggregate + non-aggregate expressions can be mixed in places where they should not be allowed to #1586
This issue can be reproduced on Rust's stable channel. (Your issue will be
closed if this is not the case)
This issue can be reproduced without requiring a third party crate
The text was updated successfully, but these errors were encountered: