A
A
Alexey Skobkin2015-10-26 12:51:23
symfony
Alexey Skobkin, 2015-10-26 12:51:23

How to do SELECT COUNT(DISTINCT(field1, field2)) in Doctrine2 DQL?

In a native PostgreSQL query, you can easily do

SELECT COUNT(DISTINCT(t.field1, t.field2)) FROM table t;

In DQL, with the same construction, an exception is thrown:
QueryException: [Syntax Error] line 0, col 22: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got 'o'

Can this be done in DQL?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ostin, 2015-10-26
@skobkin

First, the parentheses are not needed for the DISTINCT expression.
Secondly, DISTINCT in Doctrine does not support multiple arguments
. Thirdly, there is a hack to solve the previous two:

SELECT COUNT(DISTINCT CONCAT(t.field1, t.field2)) FROM table t;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question