Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ordering with arithmetic expression  #8011

@sgehrig

Description

@sgehrig

Bug Report

Q A
BC Break no
Version v2.7.0

Summary

Ordering with arithmetic expression does not work as I'd expect it to work after reading the DQL EBNF.

Current behavior

This is a simplified example of the actual query.

SELECT 
    j,
    (SELECT SUM(i.amount) FROM Invoice i WHERE i.job = j) AS HIDDEN invoiced_amount,
    (SELECT COALESCE(SUM(t.orderedAmount), j.orderedAmount) FROM Task t WHERE t.job = j) AS HIDDEN current_ordered_amount
FROM Jobs j
ORDER BY  current_ordered_amount - invoiced_amount ASC

Running the query, [Syntax Error] line 0, col xxx: Error: Expected end of string, got '-' is thrown.

How to reproduce

Run a query similar so the one above with an arithmetic expression in the ORDER BY clause.

Expected behavior

I'd expect the query to work because of what's stated in the documentation:

OrderByClause ::= "ORDER" "BY" OrderByItem {"," OrderByItem}*
OrderByItem ::= (SimpleArithmeticExpression | ...) ["ASC" | "DESC"]
SimpleArithmeticExpression ::= ArithmeticTerm {("+" | "-") ArithmeticTerm}*
ArithmeticTerm ::= ArithmeticFactor {("*" | "/") ArithmeticFactor}*
ArithmeticFactor ::= [("+" | "-")] ArithmeticPrimary
ArithmeticPrimary ::= ... | ResultVariable | ...
/* ResultVariable identifier usage of mapped field aliases (the "total" of "COUNT(*) AS total") */
ResultVariable = identifier

Is there something I missed? Or misinterpreted?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions