Error if use IN-clause inside a SUM function #6140

Closed
opened 2026-01-22 15:27:33 +01:00 by admin · 1 comment
Owner

Originally created by @webgnome on GitHub (Dec 19, 2018).

Originally assigned to: @Ocramius on GitHub.

I want to order my result by by the sum of condition matches

SUM(some_column IN (val1, val2, val3))

As i understand the code of symfonys doctrine Bundle the "AVG" | "MAX" | "MIN" | "SUM" | "COUNT functions do only except DISTINCT inside the sum parenthesis.

At the moment i use

entityManager->getConnection()->prepare(...) ...->execute ...

After that i have to do a second call over the repository class

  1. Am i Right with my assumptions?
  2. Is there any way to use an IN-clause inside the sum function without bypassing the ORM?
  3. Can this be a new feature, or is it a Bug?
Originally created by @webgnome on GitHub (Dec 19, 2018). Originally assigned to: @Ocramius on GitHub. I want to order my result by by the sum of condition matches `SUM(some_column IN (val1, val2, val3))` As i understand the code of symfonys doctrine Bundle the "AVG" | "MAX" | "MIN" | "SUM" | "COUNT functions do only except DISTINCT inside the sum parenthesis. At the moment i use ` entityManager->getConnection()->prepare(...) ...->execute ... ` After that i have to do a second call over the repository class 1. Am i Right with my assumptions? 2. Is there any way to use an IN-clause inside the sum function without bypassing the ORM? 3. Can this be a new feature, or is it a Bug?
admin added the New FeatureWon't FixQuestion labels 2026-01-22 15:27:33 +01:00
admin closed this issue 2026-01-22 15:27:33 +01:00
Author
Owner

@Ocramius commented on GitHub (Dec 19, 2018):

Am i Right with my assumptions?

Correct, DISTINCT isn't allowed there.

Is there any way to use an IN-clause inside the sum function without bypassing the ORM?

It is OK to use SQL for such computations

Can this be a new feature, or is it a Bug?

It's a won't fix upfront, since SUM(expr) is not really supported by all vendors. If you want to support it, you'd start by providing test scenarios, and verifying that they run on all DBAL platforms.

Meanwhile, closing here, since relying on SQL is an acceptable/simple tradeoff.

@Ocramius commented on GitHub (Dec 19, 2018): > Am i Right with my assumptions? Correct, `DISTINCT` isn't allowed there. > Is there any way to use an IN-clause inside the sum function without bypassing the ORM? It is OK to use SQL for such computations > Can this be a new feature, or is it a Bug? It's a `won't fix` upfront, since `SUM(expr)` is not really supported by all vendors. If you want to support it, you'd start by providing test scenarios, and verifying that they run on all DBAL platforms. Meanwhile, closing here, since relying on SQL is an acceptable/simple tradeoff.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6140