mysql (nonrendered) cast loses operator precedence

Issue #2467 resolved
Cory Stone created an issue

I ran into an issue with cast and mysql. The basic idea is:

inner_expression that evaluates to a simple add: 4 + 2 cast(inner_expression as Float) / 2

If mysql decides it doesn't need the cast for whatever reason, inner_expression is not grouped, which messes with the operator precedence, so the rendered sql looks like: 4 + 2 / 2 instead of (4 + 2) / 2.

Using sqlalchemy 0.7.6 with mysql 5.1.

I worked around this issue by just casting the first item in inner_expression to float instead of the whole expression. I also was able to work around it by calling self_group() on inner_expression.

Comments (3)

  1. Log in to comment