英文:
diesel.rs use select max with other arguments
问题
I implemented the MySQL query in Rust, but selecting causes an error. The error message is: "the trait diesel::expression::MixedAggregates<diesel::expression::is_aggregate::Yes>
is not implemented for diesel::expression::is_aggregate::No
." The error doesn't occur when I don't include progress::onemoreid
in the select statement.
英文:
i have implemented the mysql query in rust, but i select causes an error.
This is the error the trait `diesel::expression::MixedAggregates<diesel::expression::is_aggregate::Yes>` is not implemented for `diesel::expression::is_aggregate::No
Whats the problem and how can i fix this?
let sub = progress::table
.filter(progress::user.eq(1))
.group_by(progress:: otherid)
.select((diesel::dsl::max(progress::updated), progress::otherid, progress::onemoreid));
SELECT otherid, onemoreid, MAX(updated) AS newest_updated
FROM progress
WHERE user = 1
GROUP BY otherid
EDIT: the error doesnt occur when i dont have progress::onemoreid in select.
答案1
得分: 1
The relevant part from diesel documentation is the following paragraph:
> Diesel follows postgresql’s group by semantic, this means any column appearing in a group by clause is considered to be aggregated. If a primary key is part of the group by clause every column from the corresponding table is considerd to be aggregated. Select clauses cannot mix aggregated and non aggregated expressions.
This restriction is in place because otherwise your query could return non-deterministic results. After all, what value of onemoreid
should be selected when the query produces multiple possible values.
MySQL allows to write such queries, but they can return non-deterministic results there. That means that just some value is returned. Possibly even different values for the execution of the same query using the same data.
英文:
The relevant part from diesel documentation is the following paragraph:
> Diesel follows postgresql’s group by semantic, this means any column appearing in a group by clause is considered to be aggregated. If a primary key is part of the group by clause every column from the corresponding table is considerd to be aggregated. Select clauses cannot mix aggregated and non aggregated expressions.
This restriction is in place because otherwise your query could return non-deterministic results. After all, what value of onemoreid
should be selected when the query produces multiple possible values.
MySQL allows to write such queries, but they can return non-deterministic results there. That means that just some value is returned. Possibly even different values for the execution of the same query using the same data.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论