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
Common Table Expressions and .count() #1809
Comments
Ahh, yeah, I'd suggest just modifying your own SQL in the meantime as a workaround, e.g., to get the count, just write a query that looks like |
Thanks for the suggestion, but I first noticed this when using |
Ehh, or you could subclass |
I ended up re-writing the query to not use CTEs. Do you have any interest in fixing CTEs with |
I'm leaving the issue open for now as I believe there's a bug here. I just haven't figured out yet how to address it. |
A similar issue is reported by @iksteen in #1838. Since these are closely related, I'm including the issue description here: Consider the following example (note that this is obviously a silly example, but just enough to show the problem):
The generated SQL for the prefetch of Attachment will be:
While the CTE queries and the subquery themselves do get extra parentheses, the base query is not parenthesized leaving the The expected query would be:
|
Hey, thank for writing this great library!
I'm trying to use a CTE and .count() and it's not clear to me if this is supposed to work:
The
q2.count()
query looks likeSELECT COUNT(1) FROM WITH "users" AS ((SELECT "t1"."id" FROM "user" AS "t1")) (SELECT 1 FROM "user" AS "t2" INNER JOIN "users" ON ("t2"."id" = "users"."id")) AS "_wrapped"
where I would have expected
WITH "users" AS ((SELECT "t1"."id" FROM "user" AS "t1")) SELECT COUNT(1) FROM (SELECT 1 FROM "user" AS "t2" INNER JOIN "users" ON ("t2"."id" = "users"."id")) AS "_wrapped"
The docs do indeed say that .count() here will just wrap it in a COUNT thing, but I would have expected it to wrap more like my second query there. Am I calling count() wrong?
The text was updated successfully, but these errors were encountered: