DDC-330: SIZE(collection) generates wrong SQL with COUNT over several fields #408

Closed
opened 2026-01-22 12:37:22 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 14, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user @beberlei:

When using SIZE() it generates wrong sql when more than one join column appears, none of our supported database allows an expression of the kind: COUNT(p.friend*id, p.person*id)

However this happens in a case where you call size on a ManyToMany relation:

        $dql = 'SELECT p.department, AVG(p.salary) AS avgSalary FROM Doctrine\Tests\Models\Company\CompanyEmployee p '.
               'GROUP BY p.department HAVING SUM(p.salary) > 200000';

Or when the One To Many Join has more than one join column.

My idea: Use count(*) since the problem of NULL is not a problem because of the WHERE condition that explicitly prevents NULLs from appearing in these kind of queries anyways.

Originally created by @doctrinebot on GitHub (Feb 14, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user @beberlei: When using SIZE() it generates wrong sql when more than one join column appears, none of our supported database allows an expression of the kind: `COUNT(p.friend*id, p.person*id)` However this happens in a case where you call size on a ManyToMany relation: ``` $dql = 'SELECT p.department, AVG(p.salary) AS avgSalary FROM Doctrine\Tests\Models\Company\CompanyEmployee p '. 'GROUP BY p.department HAVING SUM(p.salary) > 200000'; ``` Or when the One To Many Join has more than one join column. My idea: Use count(*) since the problem of NULL is not a problem because of the WHERE condition that explicitly prevents NULLs from appearing in these kind of queries anyways.
admin added the Bug label 2026-01-22 12:37:22 +01:00
admin closed this issue 2026-01-22 12:37:23 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 14, 2010):

Comment created by @beberlei:

Fixed.

@doctrinebot commented on GitHub (Feb 14, 2010): Comment created by @beberlei: Fixed.
Author
Owner

@doctrinebot commented on GitHub (Feb 14, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 14, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#408