mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[Feature request][DQL] Support CoalesceExpression in ORDER BY #5168
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 @stof on GitHub (Jun 28, 2016).
The ORDER BY clause allows to use functions. Today, I tried to use
COALESCEthere, thinking that it was a function (which it is in SQL). However, the DQL parser implements it as a dedicated type (a CoalesceExpression) rather than a function. Because of that, using Coalesce does not work in ORDER BY clauses.It would be great to support it.
@Ocramius commented on GitHub (Jun 28, 2016):
SELECT COALESCE(yadda, yadda) AS HIDDEN thing FROM ... ORDER BY thing ASC?@stof commented on GitHub (Jun 28, 2016):
yeah, this is the workaround I used. But it would be great to support it properly (it is not different than a function in my opinion).
Btw, the same is true for
NULLIF(andCASE)@Ocramius commented on GitHub (Jun 28, 2016):
We don't support any kind of expression in the
ORDER BYclause, as far as I can remember. I'm unsure what DB platform support looks like there...@stof commented on GitHub (Jun 28, 2016):
You are wrong (remembering older versions maybe ?). Here is the EBNF:
As you can see, FunctionDeclaration is supported (which is how function calls are represented in DQL, which is a weird name as it does not declare anything)
@Ocramius commented on GitHub (Jun 30, 2016):
Hmm... fairly sure that
ScalarExpressionwon't work inOrderByItem... Do you know of any tests verifying it? I think the docs may be wrong here.@simonsolutions commented on GitHub (Jul 9, 2024):
Even if it's an old issue, I came across this problem today too. Using ORM 3.2.1 and DBAL 4.0.4 with MySQL/MariaDB (both).
Orderby doesn't support COALESCE even when mysql can handle it in a direct request. Working around with a coalescing CASE-WHEN does the job.
So functions are possible in order-by clause. It would be great to have the coalesce there also possible, and not having to use a workaround with case.