orm icon indicating copy to clipboard operation
orm copied to clipboard

$qb->expr()->countDistinct() fails with multiple values

Open greeny opened this issue 10 years ago • 4 comments

I have $qb (QueryBuilder), and i call this:

$qb->expr()->countDistinct('e.name', 'e.value')

Generated SQL / DQL is valid, but Parser complains about syntax error:

Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','

In tests, there is a test for multiple arguments in countDistinct(), but no test for Parser accepting multiple arguments for COUNT(DISTINCT

greeny avatar Dec 10 '15 14:12 greeny

Still not solved? Any work around?

oskargunther avatar Jan 20 '18 13:01 oskargunther

I found a major hack of a workaround. If you combine the two fields and then select distinct of the two it works. COUNT(DISTINCT CONCAT(ps.date, s.id))

lart2150 avatar Feb 09 '18 18:02 lart2150

It would be amazing if someone could send us a failing test case that reproduces that behaviour. It would help us a lot to identify and fix the issue you're describing.

You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket

lcobucci avatar Feb 22 '18 10:02 lcobucci

It would be amazing if someone could send us a failing test case that reproduces that behaviour. It would help us a lot to identify and fix the issue you're describing.

@lcobucci necro post #8058

peter-gribanov avatar Jan 02 '25 08:01 peter-gribanov