diff --git a/compliance/expressions/valid.txt b/compliance/expressions/valid.txt index 598a8ec57..a717a4619 100644 --- a/compliance/expressions/valid.txt +++ b/compliance/expressions/valid.txt @@ -61,6 +61,8 @@ ROUND(x, 2) # Operators and predicates first_name || ' ' || last_name +'Total: ' || qty * price || ' EUR' +a || b + c - d || e x % 2 -x + +y * (z - 1) / 2 a <> b AND a != b AND a <= b AND a >= b diff --git a/core-spec/grammar/OssieExpression.g4 b/core-spec/grammar/OssieExpression.g4 index 1084b7901..5e080f887 100644 --- a/core-spec/grammar/OssieExpression.g4 +++ b/core-spec/grammar/OssieExpression.g4 @@ -31,8 +31,8 @@ options { caseInsensitive = true; } // // Operands of comparisons and predicates are arithmetic expressions: `a = b = c` needs parentheses. // -// Precedence follows the list in the spec. The spec does not say where `||` sits: it is parsed at -// the level of + and -. +// Precedence follows the list in the spec. The spec does not say where `||` sits: it is parsed at a +// level of its own below + and -, as in sqlglot and PostgreSQL: `a || b + c` is `a || (b + c)`. expression : expr EOF @@ -58,7 +58,8 @@ valueExpr : primary # primaryValue | op=(PLUS | MINUS) valueExpr # unaryValue | valueExpr op=(STAR | SLASH | PERCENT) valueExpr # multiplicativeValue - | valueExpr op=(PLUS | MINUS | CONCAT) valueExpr # additiveValue + | valueExpr op=(PLUS | MINUS) valueExpr # additiveValue + | valueExpr CONCAT valueExpr # concatValue ; primary diff --git a/core-spec/grammar/README.md b/core-spec/grammar/README.md index 2aee50114..9140f6016 100644 --- a/core-spec/grammar/README.md +++ b/core-spec/grammar/README.md @@ -36,7 +36,8 @@ generated parser is not committed. The precedence levels follow the list in the spec's "Operator Precedence" section. Two points are not decided there: -- `||` is accepted, at the level of `+` and `-`. The spec's portable form is `CONCAT(a, b)`; +- `||` is accepted, at a level of its own below `+` and `-` (above comparisons), like sqlglot and + PostgreSQL: `a || b + c` is `a || (b + c)`. The spec's portable form is `CONCAT(a, b)`; `a || b` only appears as a dialect form. - Comparisons do not chain: `a = b = c` needs parentheses.