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
Querybuilder generating syntax errors #3501
Comments
when you use But your order by doesn't look complex. In your case what is |
When I try it that way, I get the following error:
Any ideas? |
I think it's because the ORDER BY clause is getting added to the wrapped query. If it's added to the inner query, I think it should work. |
Is there a workaround for this? |
It should work fine if you use |
I think @robbyemmert is right, the @Entity("myEntity", {
orderBy: {
createdDate: "ASC"
}
} and that broke it too even when no |
Came across this nasty bug - left comment at this PR instead. |
We also faced such a problem ( |
yeah, same here. Suppose such case: |
any solution for this? I'm having the same issue. Is there a way to resolve this? |
I'm still having this exact issue. And finding wonky behavior when using |
Sorry, I forgot to update this issue, but I've been able to work around this by adding an alias to my orderBy: const reviews = await connection
.getRepository(Review)
.createQueryBuilder("review")
.leftJoinAndSelect("review.book", "book")
.orderBy({ "review.rating": "DESC" })
.skip(10)
.take(20)
.getMany();
|
Looking at the last comment, while the alias format is working it is still failing for me when I have to wrap the alias into
|
Replacing |
|
I had a similar problem... mine was having an I have added your suggestion and my query now works Thanks! |
Your time blocking the thread, bandwidth utilization, memory usage and electricity bill will also have a complexity of Seriously though, unless you only ever have a couple of entries in your database you should never do this. Let your database crunch the data - that's what it's for after all. |
This worked for me: #747 (comment) For some reason the combination of JOIN + ORDERBY + TAKE/SKIP Try changing orderBy to "table_name.attributeName" - hopefully it works! |
I'm experiencing these issues with most recent versions of MySQL where an
|
Actually this helped. Switching my order by column from Thanks |
Also experiencing this issue. None of the provided workarounds that don't use limit/offset work for me though -- i have joins. |
I could find a workaround for my case. I am using complex
And I could fix it using
Hope this helps |
Just wondering why it still exists,🤣(I can reproduce it in mysql server v8) Thanks @garlou, you trick did work! Quickfix summary:
|
Issue type:
[ x] question
[x ] bug report
[ ] feature request
[x ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[ x]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[ ]
latest
[ ]
@next
[ ]
^0.2.7
QueryBuilder.getMany() and .getManyAndCount() are both wrapping my queries in a SELECT DISTINCT clause, which breaks my query when I use .orderBy. It's deceptive, because it's formatting the SQL different from .getSql(). The SQL from .getSql() works just fine when I run it manually.
I'm not sure why queryBuilder is wrapping my query in a SELECT DISTINCT clause... Is there a reason for this, or a way to disable it?
I'm not sure if this is a bug, question, or just something that needs better documentation.
Can .orderBy be used with queryBuilder?
My Code:
The SQL as defined by .getSql() (Which works):
The SQL that is actually hitting my database when using .getMany() or .getManyAndCount() (and failing)
The associated logging error:
Thanks in advance!
The text was updated successfully, but these errors were encountered: