DDC-1523: Coalesce() does not work with functions #1913

Closed
opened 2026-01-22 13:30:43 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 9, 2011).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user bountin:

I wanted to use COALESCE in DQL with a function (e.g. CURRENT_TIMESTAMP()). If I run this DQL, I receive a syntax error exception like this one:

montbook:marlow mprebio$ php scripts/doctrine.php orm:run-dql "select COALESCE(CURRENT_TIMESTAMP()) from Project\Entity\User user"

[Doctrine\ORM\Query\QueryException]
[Syntax Error] line 0, col 33: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '('

I've traced this error to Doctrine\ORM\Parser::ScalarExpression() which tries to interpret the current_timestamp function as a SimpleArithmeticExpression or as a StateFieldPathExpression (first if). As far as I understand this part of the parser, the function call should lead to the if part with $this->_isFunction(). Therefore I added a "and !$this->_isFunction()" to the first if clause. After this change everything works as expected: The above query returns the current timestamp (many times because of the from since DQL needs a from part).

Reordering the ifs should work too.

Originally created by @doctrinebot on GitHub (Dec 9, 2011). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user bountin: I wanted to use COALESCE in DQL with a function (e.g. CURRENT_TIMESTAMP()). If I run this DQL, I receive a syntax error exception like this one: montbook:marlow mprebio$ php scripts/doctrine.php orm:run-dql "select COALESCE(CURRENT_TIMESTAMP()) from Project\Entity\User user" [Doctrine\ORM\Query\QueryException] [Syntax Error] line 0, col 33: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '(' I've traced this error to Doctrine\ORM\Parser::ScalarExpression() which tries to interpret the current_timestamp function as a SimpleArithmeticExpression or as a StateFieldPathExpression (first if). As far as I understand this part of the parser, the function call should lead to the if part with $this->_isFunction(). Therefore I added a "and !$this->_isFunction()" to the first if clause. After this change everything works as expected: The above query returns the current timestamp (many times because of the from since DQL needs a from part). Reordering the ifs should work too.
admin added the Bug label 2026-01-22 13:30:43 +01:00
admin closed this issue 2026-01-22 13:30:44 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 9, 2011):

Comment created by bountin:

Also the documentation at http://www.doctrine-project.org/docs/orm/2.1/en/ only mentions COALESCE in the EBNF but not in the real documentation part. At first I thought that Doctrine doesn't support coalesce at all.

@doctrinebot commented on GitHub (Dec 9, 2011): Comment created by bountin: Also the documentation at http://www.doctrine-project.org/docs/orm/2.1/en/ only mentions COALESCE in the EBNF but not in the real documentation part. At first I thought that Doctrine doesn't support coalesce at all.
Author
Owner

@doctrinebot commented on GitHub (Dec 10, 2011):

Comment created by @guilhermeblanco:

COALESCE does not exist on 2.1.
COALESCE is a 2.2-DEV, so use latest master.

Marking as invalid, since we won't change 2.1 to support this.

@doctrinebot commented on GitHub (Dec 10, 2011): Comment created by @guilhermeblanco: COALESCE does not exist on 2.1. COALESCE is a 2.2-DEV, so use latest master. Marking as invalid, since we won't change 2.1 to support this.
Author
Owner

@doctrinebot commented on GitHub (Dec 10, 2011):

Issue was closed with resolution "Invalid"

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

No dependencies set.

Reference: doctrine/archived-orm#1913