Skip to content


DDC-1474: Selecting expressions involving the unary minus operator will not work, whereas the EBNF syntax definitions for DQL say they should #2104

doctrinebot opened this Issue · 2 comments

1 participant


Jira issue originally created by user dalvarez:

DQL queries like:

SELECT - someEntity.someNumericField FROM \SomeEntity someEntity

will result in a syntax error:

[Syntax Error] line 0, col 7: Error: Expected IdentificationVariable | StateFieldPathExpression | AggregateExpression | "(" Subselect ")" | ScalarExpression, got '-''

I think this should work, because the relevant EBNF definitions state the following:

SimpleSelectExpression  ::= ScalarExpression | IdentificationVariable |
                            (AggregateExpression [["AS"] AliasResultVariable])
ScalarExpression       ::= SimpleArithmeticExpression | StringPrimary | DateTimePrimary | StateFieldPathExpression
                           BooleanPrimary | EntityTypeExpression | CaseExpression
SimpleArithmeticExpression ::= ArithmeticTerm {("<ins>" | "-") ArithmeticTerm}*
ArithmeticTerm             ::= ArithmeticFactor {("**" | "/") ArithmeticFactor}**
ArithmeticFactor           ::= [("</ins>" ]( "-")) ArithmeticPrimary
ArithmeticPrimary          ::= SingleValuedPathExpression | Literal | "(" SimpleArithmeticExpression ")"
                               | FunctionsReturningNumerics | AggregateExpression | FunctionsReturningStrings
                               | FunctionsReturningDatetime | IdentificationVariable | InputParameter | CaseExpression
SingleValuedPathExpression                ::= StateFieldPathExpression | SingleValuedAssociationPathExpression
StateFieldPathExpression                  ::= IdentificationVariable "." StateField | SingleValuedAssociationPathExpression "." StateField

Therefore, the expression "- someEntity.someField" is a legitimate arithmetic factor, which ultimately should be a legitimate scalar expression too, which is a legitimate simple select expression.

Fortunately, this is easy to work around, by simply subtracting from zero, like in:

SELECT 0 - someEntity.someNumericField FROM \SomeEntity someEntity

Comment created by @beberlei:



Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.1.3 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.