CONCAT with COUNT, SUM,


CONCAT with COUNT, SUM,



In a complex query, I have a subquery to count/summarize children:


->addSelect('(SELECT CONCAT(COUNT(c.id), '|', SUM(c.field1), '|', SUM(c.field2), '|', SUM(c.field3)) FROM AppEntityChild c WHERE c.parent = p.id GROUP BY c.parent)')



This query worked perfectly until I upgraded to the new version of Symfony (4.2) and doctrine orm 2.6.1. I got the following error:


[Syntax Error] line 0, col 25: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got 'COUNT'



I tried to use CAST ... AS CHAR(25) but it doesn't work (got the same error).
Anyone can help me please?



Best regards,
Jonathan




2 Answers
2



Looks Like it is regression in doctrine StringPrimary parser function.
After looking at code I have made comment with my observation in issue related to this problem (while not entierly describing it).



Essentially new function missing this part, and defaulting to error when encountering any aggregate functions:


default:
if ($this->isAggregateFunction($lookaheadType)) {
return $this->AggregateExpression();
}



PS. link to the related issue:
https://github.com/doctrine/doctrine2/issues/7205



I found a workaround: I install doctrine extensions and I replace CONCAT by CONCAT_WS (DoctrineExtensionsQueryMysqlConcatWs).
Best regards






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages