You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
parser: arithmetic on the right-hand side of a comparison fails (WHERE a = 1 + 2) #596
An arithmetic expression on the right-hand side of a comparison fails to parse. The left-hand side and the SELECT list are fine.
Reproduced on main (c0bb385) and v1.14.0 with gosqlx.Parse:
SQL
Result
SELECT * FROM t WHERE a = 1 + 2
E2002 ... column 29: expected statement, got PLUS
SELECT * FROM t WHERE a = b * 2
expected statement, got MUL
SELECT * FROM t WHERE a > b - 1
expected statement, got MINUS
SELECT * FROM t WHERE (a = 1 + 2)
expected ), got PLUS
SELECT * FROM t WHERE a + 1 = 2
parses
SELECT a + 1 FROM t
parses
SELECT * FROM t WHERE a = (1 + 2)
parses
It also breaks placeholder arithmetic such as a = :1 + :2, a = $1 + 1 and a = ? + 1.
Likely cause
The comparison operand on the right is parsed at a precedence level that stops before additive/multiplicative operators, and the statement then ends at the +/*/- token. The fix belongs in the binary-operator precedence chain in pkg/sql/parser (comparison should parse its right operand with the additive level, not the primary level).
Expected
All of the above parse, with a = (1 + 2) precedence (arithmetic binds tighter than comparison), across all dialects; SQL() round-trips.
Found during the pre-merge review of #595 (not caused by it). Tracked from #566.
Activity
fix(parser,ast,formatter): accept GROUPS frames, EXCLUDE clause and I…
fix(parser,ast,formatter): named window round-trip, GROUPS/EXCLUDE fr…
fix(parser): parse arithmetic on the right-hand side of comparisons (#…