I use Symfony 2 and the ORM Doctrine. I want to create and register a custom DQL function. In fact, I want to use the SQL function \"CAST\" in my request, like this :
Can't find the reference but functions are not allowed in the order by clause. You need to cast your value in the select statement then sort by it.
Something like:
$qb->select('d, CAST(d.myField AS UNSIGNED) AS sortx)
->from('\Test\MyBundle\Entity\MyEntity', 'd')
->orderBy('sortx, 'ASC')
That is assuming your CAST function is written correctly.