Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error when grouping aliased fields #3769

Open
3 tasks done
SuperPommeDeTerre opened this issue Aug 31, 2023 · 0 comments
Open
3 tasks done

Compilation error when grouping aliased fields #3769

SuperPommeDeTerre opened this issue Aug 31, 2023 · 0 comments
Labels

Comments

@SuperPommeDeTerre
Copy link

Setup

Versions

  • Rust: 1.72
  • Diesel: 2.1.1
  • Database: PostgreSQL v15.3
  • Operating System: Debian 12.1 on WSL2 on Windows 10 22H2

Feature Flags

  • diesel: ["postgres", "r2d2"]

Problem Description

It's not possible to use an aliased table's column in a group by clause.

What are you trying to accomplish?

I'm trying to select aliased field grouped by anothers aliased fields.

What is the expected output?

No compilation errors.

What is the actual output?

Failed compilation log:

   Compiling bug-report v0.1.0 (/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report)
error[E0277]: the trait bound `AliasedField<users_alias, users::columns::id>: ValidGrouping<(AliasedField<users_alias, users::columns::id>, AliasedField<users_alias, users::columns::name>)>` is not satisfied
  --> src/main.rs:42:10
   |
42 |         .select((
   |          ^^^^^^ the trait `ValidGrouping<(AliasedField<users_alias, users::columns::id>, AliasedField<users_alias, users::columns::name>)>` is not implemented for `AliasedField<users_alias, users::columns::id>`
   |
   = help: the following other types implement trait `ValidGrouping<GroupByClause>`:
             <AliasedField<S, C> as ValidGrouping<()>>
             <AliasedField<S, C2> as ValidGrouping<AliasedField<S, C1>>>
   = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `ValidGrouping<(AliasedField<users_alias, users::columns::id>, AliasedField<users_alias, users::columns::name>)>`
   = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to 
implement `SelectDsl<(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)>`
   = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-7660757021989249395.txt'

error[E0271]: type mismatch resolving `<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, ...>, ...>>> as AppearsInFromClause<...>>::Count == Once`   
  --> src/main.rs:42:10
   |
42 |         .select((
   |          ^^^^^^ expected `Never`, found `Once`
   |
note: required for `comments::columns::id` to implement `AppearsOnTable<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
  --> src/schema.rs:12:9
   |
12 |         id -> Int4,
   |         ^^
   = note: 2 redundant requirements hidden
   = note: required for `NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>` to implement `AppearsOnTable<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
   = note: required for `NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
   = note: 1 redundant requirement hidden
   = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, 
AliasedField<comments_alias, comments::columns::user>>>>>`
   = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to 
implement `SelectDsl<(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)>`
   = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-7660757021989249395.txt'

error[E0277]: the trait bound `comments::columns::id: SelectableExpression<query_source::impls_which_are_only_here_to_improve_error_messages::this_table_doesnt_appear_in_the_from_clause_of_your_query>` is not satisfied
  --> src/main.rs:42:10
   |
42 |         .select((
   |          ^^^^^^ the trait `SelectableExpression<query_source::impls_which_are_only_here_to_improve_error_messages::this_table_doesnt_appear_in_the_from_clause_of_your_query>` is not implemented for `comments::columns::id`
   |
   = help: the following other types implement trait `SelectableExpression<QS>`:
             <comments::columns::id as SelectableExpression<comments::table>>
             <comments::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, Inner>>>
             <comments::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>>
             <comments::columns::id as SelectableExpression<SelectStatement<FromClause<From>>>>
             <comments::columns::id as SelectableExpression<JoinOn<Join, On>>>
             <comments::columns::id as SelectableExpression<Only<comments::table>>>
note: required for `comments::columns::id` to implement `SelectableExpression<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>>`
  --> src/schema.rs:12:9
   |
12 |         id -> Int4,
   |         ^^
   = note: 4 redundant requirements hidden
   = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, 
AliasedField<comments_alias, comments::columns::user>>>>>`
   = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to 
implement `SelectDsl<(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)>`
   = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-7660757021989249395.txt'

error[E0271]: type mismatch resolving `<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, Inner>, Grouped<Eq<AliasedField<users_alias, ...>, ...>>> as AppearsInFromClause<...>>::Count == Once`       
  --> src/main.rs:42:10
   |
42 |         .select((
   |          ^^^^^^ expected `Never`, found `Once`
   |
note: required for `comments::columns::id` to implement `AppearsOnTable<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
  --> src/schema.rs:12:9
   |
12 |         id -> Int4,
   |         ^^
note: required for `comments::columns::id` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
  --> src/schema.rs:12:9
   |
12 |         id -> Int4,
   |         ^^
   = note: 3 redundant requirements hidden
   = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, 
AliasedField<comments_alias, comments::columns::user>>>>>`
   = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to 
implement `SelectDsl<(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)>`
   = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-7660757021989249395.txt'

error[E0271]: type mismatch resolving `<Join<Alias<users_alias>, Alias<comments_alias>, Inner> as AppearsInFromClause<table>>::Count == Once`
  --> src/main.rs:42:10
   |
42 |         .select((
   |          ^^^^^^ expected `Never`, found `Once`
   |
note: required for `comments::columns::id` to implement `AppearsOnTable<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>>`
  --> src/schema.rs:12:9
   |
12 |         id -> Int4,
   |         ^^
note: required for `comments::columns::id` to implement `SelectableExpression<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>>`
  --> src/schema.rs:12:9
   |
12 |         id -> Int4,
   |         ^^
   = note: 4 redundant requirements hidden
   = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, 
AliasedField<comments_alias, comments::columns::user>>>>>`
   = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to 
implement `SelectDsl<(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)>`
   = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-7660757021989249395.txt'

error[E0277]: the trait bound `(Integer, diesel::sql_types::Nullable<BigInt>): load_dsl::private::CompatibleType<CommentsSearchResult, Pg>` is not satisfied
    --> src/main.rs:46:62
     |
46   |     let _comments = users_query.load::<CommentsSearchResult>(conn);
     |                                 ----                         ^^^^ the trait `load_dsl::private::CompatibleType<CommentsSearchResult, Pg>` is not implemented for `(Integer, diesel::sql_types::Nullable<BigInt>)`
     |                                 |
     |                                 required by a bound introduced by this call
     |
     = help: the following other types implement trait `load_dsl::private::CompatibleType<U, DB>`:
               (ST0,)
               (ST0, ST1)
               (ST0, ST1, ST2)
               (ST0, ST1, ST2, ST3)
               (ST0, ST1, ST2, ST3, ST4)
               (ST0, ST1, ST2, ST3, ST4, ST5)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7)
             and 24 others
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `LoadQuery<'_, _, CommentsSearchResult>`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/jlanglade/.cargo/registry/src/index.crates.io-6f17d22bba15001f/diesel-2.1.1/src/query_dsl/mod.rs:1543:15
     |
1541 |     fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
     |        ---- required by a bound in this associated function
1542 |     where
1543 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`

error[E0277]: the trait bound `AliasedField<users_alias, users::columns::id>: ValidGrouping<(AliasedField<users_alias, users::columns::id>, AliasedField<users_alias, users::columns::name>)>` is not satisfied
    --> src/main.rs:46:62
     |
46   |     let _comments = users_query.load::<CommentsSearchResult>(conn);
     |                                 ----                         ^^^^ the trait `ValidGrouping<(AliasedField<users_alias, users::columns::id>, AliasedField<users_alias, users::columns::name>)>` is not 
implemented for `AliasedField<users_alias, users::columns::id>`
     |                                 |
     |                                 required by a bound introduced by this call
     |
     = help: the following other types implement trait `ValidGrouping<GroupByClause>`:
               <AliasedField<S, C> as ValidGrouping<()>>
               <AliasedField<S, C2> as ValidGrouping<AliasedField<S, C1>>>
     = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `ValidGrouping<(AliasedField<users_alias, users::columns::id>, AliasedField<users_alias, users::columns::name>)>`
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `Query`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `LoadQuery<'_, _, CommentsSearchResult>`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/jlanglade/.cargo/registry/src/index.crates.io-6f17d22bba15001f/diesel-2.1.1/src/query_dsl/mod.rs:1543:15
     |
1541 |     fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
     |        ---- required by a bound in this associated function
1542 |     where
1543 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`

error[E0271]: type mismatch resolving `<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, ...>, ...>>> as AppearsInFromClause<...>>::Count == Once`   
    --> src/main.rs:46:62
     |
46   |     let _comments = users_query.load::<CommentsSearchResult>(conn);
     |                                 ----                         ^^^^ expected `Once`, found `Never`
     |                                 |
     |                                 required by a bound introduced by this call
     |
note: required for `comments::columns::id` to implement `AppearsOnTable<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
    --> src/schema.rs:12:9
     |
12   |         id -> Int4,
     |         ^^
     = note: 2 redundant requirements hidden
     = note: required for `NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>` to implement `AppearsOnTable<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
     = note: required for `NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
     = note: 1 redundant requirement hidden
     = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
     = note: required for `query_builder::select_clause::SelectClause<(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)>` to implement `query_builder::select_clause::SelectClauseExpression<FromClause<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>>`
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `Query`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `LoadQuery<'_, _, CommentsSearchResult>`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/jlanglade/.cargo/registry/src/index.crates.io-6f17d22bba15001f/diesel-2.1.1/src/query_dsl/mod.rs:1543:15
     |
1541 |     fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
     |        ---- required by a bound in this associated function
1542 |     where
1543 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`

error[E0277]: the trait bound `comments::columns::id: SelectableExpression<query_source::impls_which_are_only_here_to_improve_error_messages::this_table_doesnt_appear_in_the_from_clause_of_your_query>` is not satisfied
    --> src/main.rs:46:62
     |
46   |     let _comments = users_query.load::<CommentsSearchResult>(conn);
     |                                 ----                         ^^^^ the trait `SelectableExpression<query_source::impls_which_are_only_here_to_improve_error_messages::this_table_doesnt_appear_in_the_from_clause_of_your_query>` is not implemented for `comments::columns::id`
     |                                 |
     |                                 required by a bound introduced by this call
     |
     = help: the following other types implement trait `SelectableExpression<QS>`:
               <comments::columns::id as SelectableExpression<comments::table>>
               <comments::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, Inner>>>
               <comments::columns::id as SelectableExpression<query_source::joins::Join<Left, Right, LeftOuter>>>
               <comments::columns::id as SelectableExpression<SelectStatement<FromClause<From>>>>
               <comments::columns::id as SelectableExpression<JoinOn<Join, On>>>
               <comments::columns::id as SelectableExpression<Only<comments::table>>>
note: required for `comments::columns::id` to implement `SelectableExpression<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>>`
    --> src/schema.rs:12:9
     |
12   |         id -> Int4,
     |         ^^
     = note: 4 redundant requirements hidden
     = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
     = note: required for `query_builder::select_clause::SelectClause<(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)>` to implement `query_builder::select_clause::SelectClauseExpression<FromClause<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>>`
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `Query`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `LoadQuery<'_, _, CommentsSearchResult>`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/jlanglade/.cargo/registry/src/index.crates.io-6f17d22bba15001f/diesel-2.1.1/src/query_dsl/mod.rs:1543:15
     |
1541 |     fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
     |        ---- required by a bound in this associated function
1542 |     where
1543 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`

error[E0271]: type mismatch resolving `<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, Inner>, Grouped<Eq<AliasedField<users_alias, ...>, ...>>> as AppearsInFromClause<...>>::Count == Once`       
    --> src/main.rs:46:62
     |
46   |     let _comments = users_query.load::<CommentsSearchResult>(conn);
     |                                 ----                         ^^^^ expected `Once`, found `Never`
     |                                 |
     |                                 required by a bound introduced by this call
     |
note: required for `comments::columns::id` to implement `AppearsOnTable<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
    --> src/schema.rs:12:9
     |
12   |         id -> Int4,
     |         ^^
note: required for `comments::columns::id` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
    --> src/schema.rs:12:9
     |
12   |         id -> Int4,
     |         ^^
     = note: 3 redundant requirements hidden
     = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
     = note: required for `query_builder::select_clause::SelectClause<(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)>` to implement `query_builder::select_clause::SelectClauseExpression<FromClause<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>>`
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `Query`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `LoadQuery<'_, _, CommentsSearchResult>`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/jlanglade/.cargo/registry/src/index.crates.io-6f17d22bba15001f/diesel-2.1.1/src/query_dsl/mod.rs:1543:15
     |
1541 |     fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
     |        ---- required by a bound in this associated function
1542 |     where
1543 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`

error[E0271]: type mismatch resolving `<Join<Alias<users_alias>, Alias<comments_alias>, Inner> as AppearsInFromClause<table>>::Count == Once`
    --> src/main.rs:46:62
     |
46   |     let _comments = users_query.load::<CommentsSearchResult>(conn);
     |                                 ----                         ^^^^ expected `Once`, found `Never`
     |                                 |
     |                                 required by a bound introduced by this call
     |
note: required for `comments::columns::id` to implement `AppearsOnTable<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>>`
    --> src/schema.rs:12:9
     |
12   |         id -> Int4,
     |         ^^
note: required for `comments::columns::id` to implement `SelectableExpression<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, Inner>>`
    --> src/schema.rs:12:9
     |
12   |         id -> Int4,
     |         ^^
     = note: 4 redundant requirements hidden
     = note: required for `(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)` to implement `SelectableExpression<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>`
     = note: required for `query_builder::select_clause::SelectClause<(AliasedField<users_alias, users::columns::id>, NullableExpression<diesel::expression::count::count::count<Integer, comments::columns::id>>)>` to implement `query_builder::select_clause::SelectClauseExpression<FromClause<JoinOn<query_source::joins::Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<AliasedField<users_alias, users::columns::id>, AliasedField<comments_alias, comments::columns::user>>>>>>`
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `Query`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
     = note: required for `SelectStatement<FromClause<JoinOn<Join<Alias<users_alias>, Alias<comments_alias>, LeftOuter>, Grouped<Eq<AliasedField<users_alias, id>, ...>>>>, ..., ..., ..., ..., ..., ...>` to implement `LoadQuery<'_, _, CommentsSearchResult>`
     = note: the full type name has been written to '/mnt/c/_Projets/LBP/ARIANE/prj/PlanDeCharge/tmp/bug-report/target/debug/deps/bug_report-6d892d38176fbcec.long-type-8037930894730386046.txt'
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/jlanglade/.cargo/registry/src/index.crates.io-6f17d22bba15001f/diesel-2.1.1/src/query_dsl/mod.rs:1543:15
     |
1541 |     fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
     |        ---- required by a bound in this associated function
1542 |     where
1543 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `RunQueryDsl::load`

Some errors have detailed explanations: E0271, E0277.
For more information about an error, try `rustc --explain E0271`.
error: could not compile `bug-report` (bin "bug-report") due to 11 previous errors

Are you seeing any additional errors?

No.

Steps to reproduce

Cargo.toml:

[package]
name = "bug-report"
version = "0.1.0"
edition = "2021"

[dependencies]
diesel = { version = "2", features = ["postgres", "r2d2"] }
r2d2 = "0.8"

schema.rs:

// @generated automatically by Diesel CLI.

diesel::table! {
    users (id) {
        id -> Int4,
        name -> Text,
    }
}

diesel::table! {
    comments (id) {
        id -> Int4,
        user -> Int4,
        date -> Date,
        comment -> Nullable<Text>,
        parent -> Nullable<Int4>,
    }
}

diesel::joinable!(comments -> users (user));

diesel::allow_tables_to_appear_in_same_query!(
    users,
    comments,
);

main.rs:

mod schema;

use diesel::prelude::*;
use diesel::dsl;
use diesel::pg::PgConnection;
use diesel::r2d2::ConnectionManager;
use diesel::r2d2::Error;
use diesel::ConnectionError::BadConnection;
use std::env;

type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;

pub type DbConnection = r2d2::PooledConnection<ConnectionManager<PgConnection>>;

pub fn connection() -> Result<DbConnection, Error> {
    let db_url = env::var("DATABASE_URL").expect("Database URL not set. Please set the DATABASE_URL environment variable !");
    let manager = ConnectionManager::<PgConnection>::new(db_url);
    Pool::new(manager).expect("Failed to create db pool").get()
        .map_err(|e| Error::ConnectionError(BadConnection(format!("Failed getting database connection: {}", e))))
}

#[derive(Queryable)]
struct CommentsSearchResult {
    pub user: i32,
    pub name: String,
    pub comments_count: i64,
}

fn main() {
    let conn = &mut connection().unwrap();
    let (users_alias, comments_alias) = diesel::alias!(schema::users as users_alias, schema::comments as comments_alias,);
    allow_columns_to_appear_in_same_group_by_clause!(
        schema::users::id,
        schema::users::name
    );
    let mut users_query = users_alias
        .left_outer_join(comments_alias.on(users_alias.field(schema::users::id).eq(comments_alias.field(schema::comments::user))))
        .group_by((
            users_alias.field(schema::users::id),
            users_alias.field(schema::users::name)
        ))
        .select((
            users_alias.field(schema::users::id),
            dsl::count(schema::comments::id).nullable()
        ));
    let _comments = users_query.load::<CommentsSearchResult>(conn);
}

Checklist

  • 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant