mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Failed parse the condition in ORDER BY #6187
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @peter-gribanov on GitHub (Feb 26, 2019).
Originally assigned to: @Ocramius on GitHub.
Bug Report
I want calculate the number of occurrences of a char in string. But DQL is failed parse to SQL.
Summary
How to reproduce
DQL
Result SQL
DQL
Result SQL
DQL
Current behavior
Expected SQL
DQL
Current behavior
Expected SQL
@peter-gribanov commented on GitHub (Feb 26, 2019):
I can solve the problem using a hidden field, but this is not a solution.
@Ocramius commented on GitHub (Feb 26, 2019):
Duplicate of #7628
@peter-gribanov commented on GitHub (Feb 26, 2019):
This is not a question. This is a bug report.
As i said before, this is not a solution. This is a crutch.
@Ocramius please explain to me what prevents the use of expressions in sorting?
@secit-pl commented on GitHub (Feb 27, 2019):
I'm also interested the explanation of the question asked by @peter-gribanov
@peter-gribanov commented on GitHub (May 14, 2019):
@Ocramius will there be any answer to the question related to this bug?
@Ocramius commented on GitHub (May 14, 2019):
I think I referenced the wrong issue while closing, hence the confusion, sorry.
Lemme re-open here.
@Ocramius commented on GitHub (May 14, 2019):
Ah, no, the closing is correct: the other issue explains that expressions in
ORDER BYare indeed to be used by putting them in theSELECTclause and then re-using them (in SQL only) via theHIDDENclause and an alias.@peter-gribanov commented on GitHub (May 15, 2019):
@Ocramius thank. I know this and wrote about it in the description of the problem. Me and @secit-pl are interested in why such a non-standard implementation is chosen?
The standard SQL allows the use of expressions in sorting, but the Doctrine does not allow it. Why?
@Ocramius commented on GitHub (May 27, 2019):
Hmm, indeed, looked at support in downstream DBs, and they seem to be all supporting expressions in
ORDER BY(unless I'm mistaken - maybe @morozov knows more here).The DQL definitions affecting this (as of this writing) are:
Now, in theory this would parse this pretty much OK:
Since that is a:
I guess I turned a long standing parser bug into an intentional limitation, sorry!
@morozov commented on GitHub (May 28, 2019):
As long as the two values can be compared and are deterministic, there shouldn’t be any problems.
@lcobucci commented on GitHub (Oct 2, 2019):
Using a
HIDDENfield is mandatory according to our design. It's fine to discuss modifying this but it falls intoImprovementand notBugand should be implemented forv2.7orv3.0only@Ocramius commented on GitHub (Oct 2, 2019):
Closing here: I think @lcobucci's approach is simple and already solves the issue without introducing further questions about supported syntax.
@ipernet commented on GitHub (Sep 19, 2020):
If I'm not mistaken, this cannot be a workaround when using window functions with Postgres or MySQL8.
This works with such as parser:
But this does not due to the reported issue:
And the suggested workaround is not applicable then:
@ipernet commented on GitHub (Sep 19, 2020):
The parser bug may be that in the case of
OrderByItem(), a function will be detected before an expression, while it should be the opposite: expression can contain functions and thus they should be match first.ANd due to that, if the first term after the GROUP BY is a function, the expression is not parsed and this fails:
But if it is something else, the expression is parsed successfully:
A fix could be as simple as changing the "priority" of the switch statement used when iterating over tokens for
OrderByItem():This needs more testing of course but this fix works well for the current issue and when using window functions.