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

Unable to group by date #3950

Open
3 tasks done
kakalos12 opened this issue Feb 29, 2024 · 1 comment
Open
3 tasks done

Unable to group by date #3950

kakalos12 opened this issue Feb 29, 2024 · 1 comment

Comments

@kakalos12
Copy link

kakalos12 commented Feb 29, 2024

Setup

Versions

  • **Rust:1.76.0
  • **Diesel:2
  • **Database:mysql
  • Operating System

Feature Flags

  • **diesel:2

Problem Description

Thanks so much for a great project.
While working with a feature to sum all the user_transactions and create a statistics by date, I have a problem with the group_by function that I don't find any solution on the internet. Please help.

Thanks so much
This code does not compile :

   user_transactions::table
        .group_by(date(user_transactions::created_at))
        .select((
            sum(user_transactions::cash),
            date(user_transactions::created_at),
        ))
        .filter(user_transactions::user_id.eq(user_id))
        .filter(user_transactions::transaction_type.eq(UserTransactionType::Commission))
        .load::<(i64, NaiveDate)>(conn)
        .await
       .map_err(anyhow::Error::from)

What are you trying to accomplish?

What is the expected output?

What is the actual output?

.select((
| ^^^^^^ the trait IsContainedInGroupBy<user_transactions::columns::created_at> is not implemented for functions::date_and_time::date::date<user_transactions::columns::created_at>
--> app/src/repository/user_transaction.rs:48:10
|
48 | .select((
| ^^^^^^ the trait IsContainedInGroupBy<user_transactions::columns::created_at> is not implemented for functions::date_and_time::date::date<user_transactions::columns::created_at>
|
= help: the following other types implement trait IsContainedInGroupBy<T>:
<withdrawals::columns::updated_at as IsContainedInGroupBywithdrawals::columns::updated_at>
<withdrawals::columns::updated_at as IsContainedInGroupBywithdrawals::columns::created_at>
<withdrawals::columns::updated_at as IsContainedInGroupBywithdrawals::columns::notes>
<withdrawals::columns::updated_at as IsContainedInGroupBywithdrawals::columns::status>
<withdrawals::columns::updated_at as IsContainedInGroupBywithdrawals::columns::amount>
<withdrawals::columns::updated_at as IsContainedInGroupBywithdrawals::columns::user_id>
<withdrawals::columns::updated_at as IsContainedInGroupBywithdrawals::columns::id>
<withdrawals::columns::created_at as IsContainedInGroupBywithdrawals::columns::updated_at>
and 1428 others
note: required for user_transactions::columns::created_at to implement ValidGrouping<functions::date_and_time::date::date<user_transactions::columns::created_at>>
--> app/src/schema.rs:316:9
|
316 | created_at -> Timestamp,
| ^^^^^^^^^^
= note: 1 redundant requirement hidden
= note: required for (sum<Integer, cash>, date<created_at>) to implement ValidGrouping<functions::date_and_time::date::date<user_transactions::columns::created_at>>
= note: the full type name has been written to '/app/target/debug/deps/app-8840f9eb5889a010.long-type-1122692697415527159.txt'
= note: required for SelectStatement<FromClause<table>, DefaultSelectClause<FromClause<table>>, ..., ..., ..., ..., ...> to implement SelectDsl<(functions::aggregate_folding::sum::sum<diesel::sql_types::Integer, user_transactions::columns::cash>, functions::date_and_time::date::date<user_transactions::columns::created_at>)>
= note: the full type name has been written to '/app/target/debug/deps/app-8840f9eb5889a010.long-type-17702273429917501699.txt'

Are you seeing any additional errors?

Steps to reproduce

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
@kakalos12 kakalos12 added the bug label Feb 29, 2024
@weiznich weiznich added hole in api and removed bug labels Mar 1, 2024
@weiznich
Copy link
Member

weiznich commented Mar 1, 2024

Thanks for filling this Bug report.
I fear that this is currently just not supported by the built-in DSL. We certainly would accept a PR that extends what is possible to express in terms of valid GROUP BY clauses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants