GROUP CONCAT throught IN statement #4966

Closed
opened 2026-01-22 14:54:30 +01:00 by admin · 9 comments
Owner

Originally created by @miklio on GitHub (Jan 11, 2016).

Originally assigned to: @Ocramius on GitHub.

Hello, this is my pb :
Note that group concat function is a 3thd extension

...
 $andModule->add($query->expr()->in(':opList', 'GROUP_CONCAT(ov.id)'));
...

dql result like :

SELECT p, pv,ov FROM Path p 
INNER JOIN p.pathVoriam pv 
LEFT JOIN pv.voriam v 
LEFT JOIN p.pathval ov 
WHERE pv.qte >= 1 and p.actif = 1
GROUP BY p,pv 
HAVING :opList0 IN(GROUP_CONCAT(ov.id) ORDER BY p.dateAdd desc

and i have a :

Error: Expected Literal, got 'GROUP_CONCAT'

Thank u !

Originally created by @miklio on GitHub (Jan 11, 2016). Originally assigned to: @Ocramius on GitHub. Hello, this is my pb : Note that group concat function is a 3thd extension ``` ... $andModule->add($query->expr()->in(':opList', 'GROUP_CONCAT(ov.id)')); ... ``` dql result like : ``` SELECT p, pv,ov FROM Path p INNER JOIN p.pathVoriam pv LEFT JOIN pv.voriam v LEFT JOIN p.pathval ov WHERE pv.qte >= 1 and p.actif = 1 GROUP BY p,pv HAVING :opList0 IN(GROUP_CONCAT(ov.id) ORDER BY p.dateAdd desc ``` and i have a : ``` Error: Expected Literal, got 'GROUP_CONCAT' ``` Thank u !
admin added the Invalid label 2026-01-22 14:54:30 +01:00
admin closed this issue 2026-01-22 14:54:30 +01:00
Author
Owner

@Ocramius commented on GitHub (Jan 11, 2016):

GROUP_CONCAT retrieves a string, not a list of identifiers that you can pass to an IN() expression. Are you sure that you are using the correct logic here?

The correct workaround (assuming GROUP_CONCAT is what you want) is something like:

SELECT p, pv, ov, GROUP_CONCAT(ov.id) as someIdentifiers FROM Path p 
INNER JOIN p.pathVoriam pv 
LEFT JOIN pv.voriam v 
LEFT JOIN p.pathval ov 
WHERE pv.qte >= 1 and p.actif = 1
GROUP BY p,pv 
HAVING :opList0 IN(someIdentifiers) ORDER BY p.dateAdd desc
@Ocramius commented on GitHub (Jan 11, 2016): `GROUP_CONCAT` retrieves a string, not a list of identifiers that you can pass to an `IN()` expression. Are you sure that you are using the correct logic here? The correct workaround (assuming `GROUP_CONCAT` is what you want) is something like: ``` sql SELECT p, pv, ov, GROUP_CONCAT(ov.id) as someIdentifiers FROM Path p INNER JOIN p.pathVoriam pv LEFT JOIN pv.voriam v LEFT JOIN p.pathval ov WHERE pv.qte >= 1 and p.actif = 1 GROUP BY p,pv HAVING :opList0 IN(someIdentifiers) ORDER BY p.dateAdd desc ```
Author
Owner

@Ocramius commented on GitHub (Jan 11, 2016):

Closing, since this isn't an actual bug. Hope the reply above helps though :-)

@Ocramius commented on GitHub (Jan 11, 2016): Closing, since this isn't an actual bug. Hope the reply above helps though :-)
Author
Owner

@miklio commented on GitHub (Jan 11, 2016):

thanks for ur reply but :

SELECT p, pv, ov, GROUP_CONCAT(ov.id) as someIdentifiers FROM Path p 
INNER JOIN p.pathVoriam pv 
LEFT JOIN pv.voriam v 
LEFT JOIN p.pathval ov 
WHERE pv.qte >= 1 and p.actif = 1
GROUP BY p,pv 
HAVING :opList0 IN(someIdentifiers) ORDER BY p.dateAdd desc
Error: Expected Literal, got 'someIdentifiers'

:(

@miklio commented on GitHub (Jan 11, 2016): thanks for ur reply but : ``` SELECT p, pv, ov, GROUP_CONCAT(ov.id) as someIdentifiers FROM Path p INNER JOIN p.pathVoriam pv LEFT JOIN pv.voriam v LEFT JOIN p.pathval ov WHERE pv.qte >= 1 and p.actif = 1 GROUP BY p,pv HAVING :opList0 IN(someIdentifiers) ORDER BY p.dateAdd desc ``` ``` Error: Expected Literal, got 'someIdentifiers' ``` :(
Author
Owner

@deeky666 commented on GitHub (Jan 12, 2016):

@mickaelCOLLET AFAIK GROUP_CONCAT is MySQL specific and therefore not supported in DQL out of the box. You'll have to create a custom DQL function to use it in DQL. See http://stackoverflow.com/questions/10850345/symfony2-how-to-use-group-concat-in-querybuilder

@deeky666 commented on GitHub (Jan 12, 2016): @mickaelCOLLET AFAIK `GROUP_CONCAT` is MySQL specific and therefore not supported in DQL out of the box. You'll have to create a custom DQL function to use it in DQL. See http://stackoverflow.com/questions/10850345/symfony2-how-to-use-group-concat-in-querybuilder
Author
Owner

@deeky666 commented on GitHub (Jan 12, 2016):

Sorry didn't read that you are already using a custom DQL function for that. Then most probably something is wrong with that third party code. Please report an issue there.

@deeky666 commented on GitHub (Jan 12, 2016): Sorry didn't read that you are already using a custom DQL function for that. Then most probably something is wrong with that third party code. Please report an issue there.
Author
Owner

@miklio commented on GitHub (Jan 12, 2016):

i have create a custom DQL for this function and that work very well, the problem is not the group_concat function, but to pass a indentifier in the IN expr fail

@miklio commented on GitHub (Jan 12, 2016): i have create a custom DQL for this function and that work very well, the problem is not the group_concat function, but to pass a indentifier in the IN expr fail
Author
Owner

@miklio commented on GitHub (Jan 12, 2016):

Here the custom group concat function :

https://github.com/beberlei/DoctrineExtensions/blob/master/src/Query/Mysql/GroupConcat.php

@miklio commented on GitHub (Jan 12, 2016): Here the custom group concat function : https://github.com/beberlei/DoctrineExtensions/blob/master/src/Query/Mysql/GroupConcat.php
Author
Owner

@deeky666 commented on GitHub (Jan 12, 2016):

@mickaelCOLLET your query is wrong. GROUP_CONCAT returns a concatenated string, not a list of values. So using IN() does not make much sense anyways. I guess you'll have to rethink about your query and what you actually want to do.
DQL's InExpression only accepts literals and subselects.

@deeky666 commented on GitHub (Jan 12, 2016): @mickaelCOLLET your query is wrong. `GROUP_CONCAT` returns a concatenated `string`, not a list of values. So using `IN()` does not make much sense anyways. I guess you'll have to rethink about your query and what you actually want to do. DQL's `InExpression` only accepts literals and subselects.
Author
Owner

@miklio commented on GitHub (Jan 12, 2016):

Ok i see, thank u for all !

@miklio commented on GitHub (Jan 12, 2016): Ok i see, thank u for all !
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4966