Just tried to solve the same problem, and I really found a solution for PostgreSQL .
$sql = 'SELECT * FROM company WHERE COALESCE(:company_id, NULL) ISNULL OR id = :company_id;' $connection->executeQuery($sql, ['company_id' => $id]);
Based on the given $id it returns a specific company or all if null passed. The problem is that the parser does not know what you are actually going to do with the argument, therefore, passing it to the COALESCE function, it knows that it passes it to the function, so the problem is solved.
So, if he started working in a βcleanβ SQL solution, using it inside DQL should not be a problem. I have not tried it, but Doctrine should have COALESCE support, so DQL should be easily updated.
source share