-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Syntax error for simple grouping in Postgres or non-optimal sql #630
Comments
Someone commented:
The use of the variable in the group by expression tricks the compiler into thinking that there could be more than one group. |
Setting to improvement / 2.1 because the groupBy workaround should work in 2.0.1 but a more direct way to express this query would be preferable. |
This can be expressed directly in Slick 2.1 but the generated code contains a duplicate subquery. Slick does not support unification of subqueries at the moment. |
FTR, the code should look something like this:
This works in 2.1 but generates an unnecessarily complicated statement. |
Out of curiosity, what is the status of this issue (w.r.t. Slick 3.X?). I have found myself wanting to express a similarly simple statement: SELECT COUNT(T1.x), COUNT(T2.y)
FROM table1 AS T1
LEFT JOIN table2 AS T2
ON T1.x = T2.y I managed to get it working with groupBy, but couldn't figure out how to do it without. I found another related issue on SO about this (http://stackoverflow.com/questions/29278685/how-to-make-multiple-aggregations-with-slick-without-group-by), but no answers. Is this aggregation expressible in Slick 3 without groupBy and have I just missed how? Or is it unresolved for both Slick 2 and 3? If it isn't resolved, am I correct in assuming a native query would be the way to go if efficiency matters? |
No change in 3.0 or 3.1. For example, AggregateTest.testAgregates produces the following for the last query:
IOW, it works and is decently nice and efficient but there is still no unification. |
From http://stackoverflow.com/questions/21414449/aggregate-multiple-columns-without-groupby-in-slick-2-0:
I would like to perform an aggregation with Slick that executes SQL like the following:
where
table_a
has anINT
columna
In Slick given the table definition:
It seems like I have 2 options:
Query(as.min, as.max)
However, the generated sql is not good in either case. In 1, there are two separate sub-selects generated, which is like writing two separate queries. In 2, the following is generated:
However, this syntax is not correct for Postgres (it groups by the first column value, which is invalid in this case). Indeed AFAIK it is not possible to group by a constant value in Postgres, except by omitting the group by clause.
Is there a way to cause Slick to emit a single query with both aggregates without the
GROUP BY
?The text was updated successfully, but these errors were encountered: