[Syntax Error] line 0, col 28: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '(' #6004

Closed
opened 2026-01-22 15:24:34 +01:00 by admin · 13 comments
Owner

Originally created by @dancostinel on GitHub (Jun 29, 2018).

Bug Report

Q A
BC Break no
Version ~1.2

Summary

Having this dql code:

# UserRepository.php
public function testCoalesce()
{
    return $this
        ->createQueryBuilder('u')
        ->select("GROUP_CONCAT(COALESCE(u.id), 0) SEPARATOR ', '")
        ->groupBy('u.id')
        ->getQuery()
        ->getArrayResult()
    ;
}

Current behavior

When executing the query, it throws this error:
https://imgur.com/a/Odx0HJE

Seems like writing COALESCE function inside GROUP_CONCAT function is not working, even though I have the CoalesceExpression() method inside vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php class.

/**
 * CoalesceExpression ::= "COALESCE" "(" ScalarExpression {"," ScalarExpression}* ")"
 *
 * @return \Doctrine\ORM\Query\AST\CoalesceExpression
 */
public function CoalesceExpression()
{
    $this->match(Lexer::T_COALESCE);
    $this->match(Lexer::T_OPEN_PARENTHESIS);

    // Process ScalarExpressions (1..N)
    $scalarExpressions = array();
    $scalarExpressions[] = $this->ScalarExpression();

    while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
        $this->match(Lexer::T_COMMA);

        $scalarExpressions[] = $this->ScalarExpression();
    }

    $this->match(Lexer::T_CLOSE_PARENTHESIS);

    return new AST\CoalesceExpression($scalarExpressions);
}

How to reproduce

added DQL code above

If I write the equivalent SQL code inside the repo's method, then it works as expected.

#UserRepository.php
$db = $this->getEntityManager()->getConnection();
$sql = "SELECT GROUP_CONCAT(COALESCE(u.id, 0) SEPARATOR ', ') AS tst FROM User u GROUP BY u.id";
$stmt = $db->prepare($sql);
$stmt->execute();

return $stmt->fetchAll();

Please, help.

Originally created by @dancostinel on GitHub (Jun 29, 2018). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |----------------| ------ | BC Break | no | Version | ~1.2 #### Summary Having this dql code: ```php # UserRepository.php public function testCoalesce() { return $this ->createQueryBuilder('u') ->select("GROUP_CONCAT(COALESCE(u.id), 0) SEPARATOR ', '") ->groupBy('u.id') ->getQuery() ->getArrayResult() ; } ``` #### Current behavior When executing the query, it throws this error: [https://imgur.com/a/Odx0HJE](url) Seems like writing COALESCE function inside GROUP_CONCAT function is not working, even though I have the ```CoalesceExpression()``` method inside ```vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php``` class. ```php /** * CoalesceExpression ::= "COALESCE" "(" ScalarExpression {"," ScalarExpression}* ")" * * @return \Doctrine\ORM\Query\AST\CoalesceExpression */ public function CoalesceExpression() { $this->match(Lexer::T_COALESCE); $this->match(Lexer::T_OPEN_PARENTHESIS); // Process ScalarExpressions (1..N) $scalarExpressions = array(); $scalarExpressions[] = $this->ScalarExpression(); while ($this->lexer->isNextToken(Lexer::T_COMMA)) { $this->match(Lexer::T_COMMA); $scalarExpressions[] = $this->ScalarExpression(); } $this->match(Lexer::T_CLOSE_PARENTHESIS); return new AST\CoalesceExpression($scalarExpressions); } ``` #### How to reproduce added DQL code above If I write the equivalent SQL code inside the repo's method, then it works as expected. ```php #UserRepository.php $db = $this->getEntityManager()->getConnection(); $sql = "SELECT GROUP_CONCAT(COALESCE(u.id, 0) SEPARATOR ', ') AS tst FROM User u GROUP BY u.id"; $stmt = $db->prepare($sql); $stmt->execute(); return $stmt->fetchAll(); ``` Please, help.
admin added the BugInvalidQuestion labels 2026-01-22 15:24:34 +01:00
admin closed this issue 2026-01-22 15:24:35 +01:00
Author
Owner

@Ocramius commented on GitHub (Jun 29, 2018):

As mentioned in the code, following is expected as parameter: $this->ScalarExpression();

A CoalesceExpression is a NullComparisonExpression, which in turn is a SimpleConditionalExpression, which is a ConditionalPrimary, which is a ConditionalFactor, which is a ConditionalTerm, which is a ConditionalExpression, which is really only used in the usual WHERE, JOIN, HAVING suspects (see https://github.com/doctrine/doctrine2/blob/v2.6.1/lib/Doctrine/ORM/Query/Parser.php) that is not guaranteed to return a scalar, from what I see

We could change COALESCE() to become a custom DQL function instead of a part of the DQL language, but that's going to break a lot of existing software.

@Ocramius commented on GitHub (Jun 29, 2018): As mentioned in the code, following is expected as parameter: `$this->ScalarExpression();` A `CoalesceExpression` is a `NullComparisonExpression`, which in turn is a `SimpleConditionalExpression`, which is a `ConditionalPrimary`, which is a `ConditionalFactor`, which is a `ConditionalTerm`, which is a `ConditionalExpression`, which is really only used in the usual `WHERE`, `JOIN`, `HAVING` suspects (see https://github.com/doctrine/doctrine2/blob/v2.6.1/lib/Doctrine/ORM/Query/Parser.php) that is not guaranteed to return a scalar, from what I see We could change `COALESCE()` to become a custom DQL function instead of a part of the DQL language, but that's going to break a lot of existing software.
Author
Owner

@Ocramius commented on GitHub (Jun 29, 2018):

Also, can you check the ORM version from your composer.lock please? ~1.2 seems incorrect.

@Ocramius commented on GitHub (Jun 29, 2018): Also, can you check the ORM version from your `composer.lock` please? `~1.2` seems incorrect.
Author
Owner

@dancostinel commented on GitHub (Jun 29, 2018):

Hi, thanks for replying.

Sure, the Doctrine/ORM version is (composer.lock):

"doctrine/orm": "~2.4",

And in composer.json (all entries related to doctrine):

"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"stof/doctrine-extensions-bundle": "^1.2"

I guess I miss-wrote the version by copying it from doctrine-bundle. Sorry about that.

@dancostinel commented on GitHub (Jun 29, 2018): Hi, thanks for replying. Sure, the Doctrine/ORM version is (composer.lock): ``` "doctrine/orm": "~2.4", ``` And in composer.json (all entries related to doctrine): ``` "doctrine/orm": "~2.2,>=2.2.3", "doctrine/doctrine-bundle": "~1.2", "stof/doctrine-extensions-bundle": "^1.2" ``` I guess I miss-wrote the version by copying it from doctrine-bundle. Sorry about that.
Author
Owner

@Ocramius commented on GitHub (Jun 29, 2018):

Sure, the Doctrine/ORM version is (composer.lock):

"doctrine/orm": "~2.4",

I think that's a version constraint only - it should be pin-pointed to a specific release, not to a range, please check again.

@Ocramius commented on GitHub (Jun 29, 2018): > Sure, the Doctrine/ORM version is (composer.lock): > > `"doctrine/orm": "~2.4",` I think that's a version constraint only - it should be pin-pointed to a specific release, not to a range, please check again.
Author
Owner

@dancostinel commented on GitHub (Jun 29, 2018):

Should be this one?

{
            "name": "doctrine/orm",
            "version": "v2.5.14",
            "source": {
                "type": "git",
                "url": "https://github.com/doctrine/doctrine2.git",
                "reference": "810a7baf81462a5ddf10e8baa8cb94b6eec02754"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/810a7baf81462a5ddf10e8baa8cb94b6eec02754",
                "reference": "810a7baf81462a5ddf10e8baa8cb94b6eec02754",
                "shasum": ""
            },
            "require": {
                "doctrine/cache": "~1.4",
                "doctrine/collections": "~1.2",
                "doctrine/common": ">=2.5-dev,<2.9-dev",
                "doctrine/dbal": ">=2.5-dev,<2.7-dev",
                "doctrine/instantiator": "^1.0.1",
                "ext-pdo": "*",
                "php": ">=5.4",
                "symfony/console": "~2.5|~3.0|~4.0"
            },
            "require-dev": {
                "phpunit/phpunit": "~4.0",
                "symfony/yaml": "~2.3|~3.0|~4.0"
            },
            "suggest": {
                "symfony/yaml": "If you want to use YAML Metadata Mapping Driver"
            },
            "bin": [
                "bin/doctrine",
                "bin/doctrine.php"
            ],
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6.x-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "Doctrine\\ORM\\": "lib/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Roman Borschel",
                    "email": "roman@code-factory.org"
                },
                {
                    "name": "Benjamin Eberlei",
                    "email": "kontakt@beberlei.de"
                },
                {
                    "name": "Guilherme Blanco",
                    "email": "guilhermeblanco@gmail.com"
                },
                {
                    "name": "Jonathan Wage",
                    "email": "jonwage@gmail.com"
                }
            ],
            "description": "Object-Relational-Mapper for PHP",
            "homepage": "http://www.doctrine-project.org",
            "keywords": [
                "database",
                "orm"
            ],
            "time": "2017-12-17T02:57:51+00:00"
        },
@dancostinel commented on GitHub (Jun 29, 2018): Should be this one? ``` { "name": "doctrine/orm", "version": "v2.5.14", "source": { "type": "git", "url": "https://github.com/doctrine/doctrine2.git", "reference": "810a7baf81462a5ddf10e8baa8cb94b6eec02754" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/810a7baf81462a5ddf10e8baa8cb94b6eec02754", "reference": "810a7baf81462a5ddf10e8baa8cb94b6eec02754", "shasum": "" }, "require": { "doctrine/cache": "~1.4", "doctrine/collections": "~1.2", "doctrine/common": ">=2.5-dev,<2.9-dev", "doctrine/dbal": ">=2.5-dev,<2.7-dev", "doctrine/instantiator": "^1.0.1", "ext-pdo": "*", "php": ">=5.4", "symfony/console": "~2.5|~3.0|~4.0" }, "require-dev": { "phpunit/phpunit": "~4.0", "symfony/yaml": "~2.3|~3.0|~4.0" }, "suggest": { "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" }, "bin": [ "bin/doctrine", "bin/doctrine.php" ], "type": "library", "extra": { "branch-alias": { "dev-master": "2.6.x-dev" } }, "autoload": { "psr-0": { "Doctrine\\ORM\\": "lib/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Roman Borschel", "email": "roman@code-factory.org" }, { "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, { "name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com" }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" } ], "description": "Object-Relational-Mapper for PHP", "homepage": "http://www.doctrine-project.org", "keywords": [ "database", "orm" ], "time": "2017-12-17T02:57:51+00:00" }, ```
Author
Owner

@Ocramius commented on GitHub (Jun 29, 2018):

Hmm, v2.5.14.

We changed some of the parsing in 2.6.0 - can you attempt an upgrade please?

@Ocramius commented on GitHub (Jun 29, 2018): Hmm, `v2.5.14`. We changed some of the parsing in `2.6.0` - can you attempt an upgrade please?
Author
Owner

@dancostinel commented on GitHub (Jun 29, 2018):

Ok, thanks for suggestion. I'll upgrade and let you know if it worked or not.

@dancostinel commented on GitHub (Jun 29, 2018): Ok, thanks for suggestion. I'll upgrade and let you know if it worked or not.
Author
Owner

@dancostinel commented on GitHub (Jun 29, 2018):

Unfortunately the error is still present:

https://imgur.com/a/Ngt2xFB

Current setup:

composer.json

"doctrine/annotations": "^1.6",
"doctrine/dbal": "^2.6",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/instantiator": "^1.1",
"doctrine/orm": "2.6.1",

composer.lock

{
            "name": "doctrine/orm",
            "version": "v2.6.1",
            "source": {
                "type": "git",
                "url": "https://github.com/doctrine/doctrine2.git",
                "reference": "87ee409783a4a322b5597ebaae558661404055a7"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/87ee409783a4a322b5597ebaae558661404055a7",
                "reference": "87ee409783a4a322b5597ebaae558661404055a7",
                "shasum": ""
            },
            "require": {
                "doctrine/annotations": "~1.5",
                "doctrine/cache": "~1.6",
                "doctrine/collections": "^1.4",
                "doctrine/common": "^2.7.1",
                "doctrine/dbal": "^2.6",
                "doctrine/instantiator": "~1.1",
                "ext-pdo": "*",
                "php": "^7.1",
                "symfony/console": "~3.0|~4.0"
            },
            "require-dev": {
                "doctrine/coding-standard": "^1.0",
                "phpunit/phpunit": "^6.5",
                "squizlabs/php_codesniffer": "^3.2",
                "symfony/yaml": "~3.4|~4.0"
            },
            "suggest": {
                "symfony/yaml": "If you want to use YAML Metadata Mapping Driver"
            },
            "bin": [
                "bin/doctrine"
            ],
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6.x-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Doctrine\\ORM\\": "lib/Doctrine/ORM"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Roman Borschel",
                    "email": "roman@code-factory.org"
                },
                {
                    "name": "Benjamin Eberlei",
                    "email": "kontakt@beberlei.de"
                },
                {
                    "name": "Guilherme Blanco",
                    "email": "guilhermeblanco@gmail.com"
                },
                {
                    "name": "Jonathan Wage",
                    "email": "jonwage@gmail.com"
                },
                {
                    "name": "Marco Pivetta",
                    "email": "ocramius@gmail.com"
                }
            ],
            "description": "Object-Relational-Mapper for PHP",
            "homepage": "http://www.doctrine-project.org",
            "keywords": [
                "database",
                "orm"
            ],
            "time": "2018-02-27T07:30:56+00:00"
        },
dan@ubuntu:/var/www/test1$ php -v
PHP 7.2.7-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun 22 2018 08:44:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.7-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
@dancostinel commented on GitHub (Jun 29, 2018): Unfortunately the error is still present: https://imgur.com/a/Ngt2xFB Current setup: composer.json ``` "doctrine/annotations": "^1.6", "doctrine/dbal": "^2.6", "doctrine/doctrine-bundle": "^1.6", "doctrine/instantiator": "^1.1", "doctrine/orm": "2.6.1", ``` composer.lock ``` { "name": "doctrine/orm", "version": "v2.6.1", "source": { "type": "git", "url": "https://github.com/doctrine/doctrine2.git", "reference": "87ee409783a4a322b5597ebaae558661404055a7" }, "dist": { "type": "zip", "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/87ee409783a4a322b5597ebaae558661404055a7", "reference": "87ee409783a4a322b5597ebaae558661404055a7", "shasum": "" }, "require": { "doctrine/annotations": "~1.5", "doctrine/cache": "~1.6", "doctrine/collections": "^1.4", "doctrine/common": "^2.7.1", "doctrine/dbal": "^2.6", "doctrine/instantiator": "~1.1", "ext-pdo": "*", "php": "^7.1", "symfony/console": "~3.0|~4.0" }, "require-dev": { "doctrine/coding-standard": "^1.0", "phpunit/phpunit": "^6.5", "squizlabs/php_codesniffer": "^3.2", "symfony/yaml": "~3.4|~4.0" }, "suggest": { "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" }, "bin": [ "bin/doctrine" ], "type": "library", "extra": { "branch-alias": { "dev-master": "2.6.x-dev" } }, "autoload": { "psr-4": { "Doctrine\\ORM\\": "lib/Doctrine/ORM" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { "name": "Roman Borschel", "email": "roman@code-factory.org" }, { "name": "Benjamin Eberlei", "email": "kontakt@beberlei.de" }, { "name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com" }, { "name": "Jonathan Wage", "email": "jonwage@gmail.com" }, { "name": "Marco Pivetta", "email": "ocramius@gmail.com" } ], "description": "Object-Relational-Mapper for PHP", "homepage": "http://www.doctrine-project.org", "keywords": [ "database", "orm" ], "time": "2018-02-27T07:30:56+00:00" }, ``` ``` dan@ubuntu:/var/www/test1$ php -v PHP 7.2.7-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun 22 2018 08:44:50) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.7-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies ```
Author
Owner

@Majkl578 commented on GitHub (Jul 11, 2018):

@dancostinel Can you please provide the code of your GROUP_CONCAT function? Or at least which library do you use that adds its implementation?
Assuming you use the popular beberlei/DoctrineExtensions, the provided syntax is invalid:

->select("GROUP_CONCAT(COALESCE(u.id), 0) SEPARATOR ', '")

should be:

->select("GROUP_CONCAT(COALESCE(u.id, 0) SEPARATOR ', ')")

If you are using another library with different syntax, this may also be fixed by https://github.com/doctrine/doctrine2/pull/7296, but I can't confirm without the code - can you test 2.6.2-dev and see if the fix also fixes your issue?
Thanks.

@Majkl578 commented on GitHub (Jul 11, 2018): @dancostinel Can you please provide the code of your GROUP_CONCAT function? Or at least which library do you use that adds its implementation? Assuming you use the popular `beberlei/DoctrineExtensions`, the provided syntax is [invalid](https://github.com/beberlei/DoctrineExtensions/blob/master/tests/Query/Mysql/GroupConcatTest.php): ``` ->select("GROUP_CONCAT(COALESCE(u.id), 0) SEPARATOR ', '") ``` should be: ``` ->select("GROUP_CONCAT(COALESCE(u.id, 0) SEPARATOR ', ')") ``` If you are using another library with different syntax, this may also be fixed by https://github.com/doctrine/doctrine2/pull/7296, but I can't confirm without the code - can you test 2.6.2-dev and see if the fix also fixes your issue? Thanks.
Author
Owner

@dancostinel commented on GitHub (Jul 12, 2018):

Hi @Majkl578 , that was just a typo in my code. You can figure out that easily, just by seeing the image with the error I received, which is for a different type of parenthesis (open-paranthesis), versus the type of parenthesis from my typo. Of course, I used DoctrineExtensions provided implementation for GROUP_CONCAT.

I'll present code again which displays the error:

[Syntax Error] line 0, col 28: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '('
#UserRepository.php
public function testCoalesce()
{
    return $this
        ->createQueryBuilder('u')
        ->select("GROUP_CONCAT(COALESCE(u.firstName, 'N/A') SEPARATOR ', ')")
        ->getQuery()
        ->getArrayResult()
    ;
}

If I remove the COALESCE part, which is:

#UserRepository.php
public function testCoalesce()
{
    return $this
        ->createQueryBuilder('u')
        ->select("GROUP_CONCAT(u.firstName SEPARATOR ', ')")
        ->getQuery()
        ->getArrayResult()
    ;
}

then everything works as expected.

@dancostinel commented on GitHub (Jul 12, 2018): Hi @Majkl578 , that was just a typo in my code. You can figure out that easily, just by seeing the image with the error I received, which is for a different type of parenthesis (open-paranthesis), versus the type of parenthesis from my typo. Of course, I used DoctrineExtensions provided implementation for GROUP_CONCAT. I'll present code again which displays the error: ``` [Syntax Error] line 0, col 28: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '(' ``` ``` #UserRepository.php public function testCoalesce() { return $this ->createQueryBuilder('u') ->select("GROUP_CONCAT(COALESCE(u.firstName, 'N/A') SEPARATOR ', ')") ->getQuery() ->getArrayResult() ; } ``` If I remove the COALESCE part, which is: ``` #UserRepository.php public function testCoalesce() { return $this ->createQueryBuilder('u') ->select("GROUP_CONCAT(u.firstName SEPARATOR ', ')") ->getQuery() ->getArrayResult() ; } ``` then everything works as expected.
Author
Owner

@Majkl578 commented on GitHub (Jul 12, 2018):

Can you please test with doctrine/orm:2.6.x-dev?

@Majkl578 commented on GitHub (Jul 12, 2018): Can you please test with `doctrine/orm:2.6.x-dev`?
Author
Owner

@Majkl578 commented on GitHub (Jul 12, 2018):

I did some further testing and this doesn't seem to have been supported by GROUP_CONCAT.
Furthermore this is not an ORM issue itself, it should be reported as a feature request / bug on beberlei/DoctrineExtensions.

As a proof, here's a diff for DoctrineExtensions with a test:

$ git diff
diff --git a/composer.json b/composer.json
index 91238d2..adb6cf3 100644
--- a/composer.json
+++ b/composer.json
@@ -9,10 +9,10 @@
         {"name": "Steve Lacey", "email": "steve@stevelacey.net"}
     ],
     "require": {
-        "php": ">=5.4"
+        "php": ">=5.4",
+        "doctrine/orm": "2.5.5"
     },
     "require-dev": {
-        "doctrine/orm": "^2.5",
         "friendsofphp/php-cs-fixer": "^2.2.19",
         "nesbot/carbon": "*",
         "phpunit/phpunit": "^4.5",
diff --git a/tests/Query/Mysql/GroupConcatTest.php b/tests/Query/Mysql/GroupConcatTest.php
index 460880e..7fbd303 100644
--- a/tests/Query/Mysql/GroupConcatTest.php
+++ b/tests/Query/Mysql/GroupConcatTest.php
@@ -37,4 +37,12 @@ class GroupConcatTest extends MysqlTestCase
             "SELECT GROUP_CONCAT(b0_.id SEPARATOR ' ') AS sclr_0 FROM Blank b0_"
         );
     }
+
+    public function testGroupConcatWithCoalesce()
+    {
+        $this->assertDqlProducesSql(
+            "SELECT GROUP_CONCAT(COALESCE(blank.id, 'N/A') SEPARATOR ', ') from DoctrineExtensions\Tests\Entities\Blank as blank",
+            "SELECT GROUP_CONCAT(COALESCE(b0_.id, 'N/A') SEPARATOR ', ') AS sclr_0 FROM Blank b0_"
+        );
+    }
 }

Fails with all of ORM 2.4.4, ORM 2.5.5, ORM 2.5.x-dev and ORM 2.6.x-dev.

You can also use IFNULL which seems to work:

SELECT GROUP_CONCAT(IFNULL(blank.id, 'N/A') SEPARATOR ', ')

Closing as invalid here, please open issue on DoctrineExtensions.

@Majkl578 commented on GitHub (Jul 12, 2018): I did some further testing and this doesn't seem to have been supported by `GROUP_CONCAT`. Furthermore this is not an ORM issue itself, it should be reported as a feature request / bug on [beberlei/DoctrineExtensions](https://github.com/beberlei/DoctrineExtensions). As a proof, here's a diff for DoctrineExtensions with a test: ```diff $ git diff diff --git a/composer.json b/composer.json index 91238d2..adb6cf3 100644 --- a/composer.json +++ b/composer.json @@ -9,10 +9,10 @@ {"name": "Steve Lacey", "email": "steve@stevelacey.net"} ], "require": { - "php": ">=5.4" + "php": ">=5.4", + "doctrine/orm": "2.5.5" }, "require-dev": { - "doctrine/orm": "^2.5", "friendsofphp/php-cs-fixer": "^2.2.19", "nesbot/carbon": "*", "phpunit/phpunit": "^4.5", diff --git a/tests/Query/Mysql/GroupConcatTest.php b/tests/Query/Mysql/GroupConcatTest.php index 460880e..7fbd303 100644 --- a/tests/Query/Mysql/GroupConcatTest.php +++ b/tests/Query/Mysql/GroupConcatTest.php @@ -37,4 +37,12 @@ class GroupConcatTest extends MysqlTestCase "SELECT GROUP_CONCAT(b0_.id SEPARATOR ' ') AS sclr_0 FROM Blank b0_" ); } + + public function testGroupConcatWithCoalesce() + { + $this->assertDqlProducesSql( + "SELECT GROUP_CONCAT(COALESCE(blank.id, 'N/A') SEPARATOR ', ') from DoctrineExtensions\Tests\Entities\Blank as blank", + "SELECT GROUP_CONCAT(COALESCE(b0_.id, 'N/A') SEPARATOR ', ') AS sclr_0 FROM Blank b0_" + ); + } } ``` Fails with all of ORM 2.4.4, ORM 2.5.5, ORM 2.5.x-dev and ORM 2.6.x-dev. You can also use `IFNULL` which seems to work: ``` SELECT GROUP_CONCAT(IFNULL(blank.id, 'N/A') SEPARATOR ', ') ``` Closing as invalid here, please open issue on DoctrineExtensions.
Author
Owner

@dancostinel commented on GitHub (Jul 12, 2018):

Ok, @Majkl578, IFNULL works for me aswell. Thanks for the effort. I will report this issue to DoctrineExtensions' page.

@dancostinel commented on GitHub (Jul 12, 2018): Ok, @Majkl578, ```IFNULL``` works for me aswell. Thanks for the effort. I will report this issue to DoctrineExtensions' page.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6004