summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/operators.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-11-25 12:20:13 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-11-25 12:20:13 -0500
commit77f641429f019d06cc467ec4e57ae94f808d70bd (patch)
tree94ddacadb8915d19d3ee3cdf7a3771fa63ba0184 /lib/sqlalchemy/sql/operators.py
parent5247c244ca6595f2685f1c0c271618eda7cb5e62 (diff)
downloadsqlalchemy-77f641429f019d06cc467ec4e57ae94f808d70bd.tar.gz
- Fixed operator precedence rules for multiple
chains of a single non-associative operator. I.e. "x - (y - z)" will compile as "x - (y - z)" and not "x - y - z". Also works with labels, i.e. "x - (y - z).label('foo')" [ticket:1984] - Single element tuple expressions inside an IN clause parenthesize correctly, also from [ticket:1984], added tests for PG - re-fix again importlater, [ticket:1983]
Diffstat (limited to 'lib/sqlalchemy/sql/operators.py')
-rw-r--r--lib/sqlalchemy/sql/operators.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index 6f70b1778..68e30e646 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -83,10 +83,14 @@ def desc_op(a):
def asc_op(a):
return a.asc()
+
_commutative = set([eq, ne, add, mul])
def is_commutative(op):
return op in _commutative
+_associative = _commutative.union([concat_op, and_, or_])
+
+
_smallest = symbol('_smallest')
_largest = symbol('_largest')
@@ -131,5 +135,8 @@ _PRECEDENCE = {
}
def is_precedent(operator, against):
- return (_PRECEDENCE.get(operator, _PRECEDENCE[_smallest]) <=
+ if operator is against and operator in _associative:
+ return False
+ else:
+ return (_PRECEDENCE.get(operator, _PRECEDENCE[_smallest]) <=
_PRECEDENCE.get(against, _PRECEDENCE[_largest]))