summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-02-05 15:49:02 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-02-05 15:49:02 +0000
commita4a38a982aa04f3d08e662c50e55be23cefcc492 (patch)
tree3f665714d23871466fe6c76566fa8dd1ffa808d2 /lib/sqlalchemy/sql
parentdfbb1fc148fa784000dfee43a194d3f8d40a0ae2 (diff)
downloadsqlalchemy-a4a38a982aa04f3d08e662c50e55be23cefcc492.tar.gz
- Added math negation operator support, -x.
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/compiler.py1
-rw-r--r--lib/sqlalchemy/sql/expression.py6
-rw-r--r--lib/sqlalchemy/sql/operators.py3
3 files changed, 9 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index e635e20e1..4486c24db 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -73,6 +73,7 @@ OPERATORS = {
# end Py2K
operators.mod : ' % ',
operators.truediv : ' / ',
+ operators.neg : '-',
operators.lt : ' < ',
operators.le : ' <= ',
operators.ne : ' != ',
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index 5c61777fe..89137d2ce 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -1363,6 +1363,9 @@ class ColumnOperators(Operators):
def __ge__(self, other):
return self.operate(operators.ge, other)
+ def __neg__(self):
+ return self.operate(operators.neg)
+
def concat(self, other):
return self.operate(operators.concat_op, other)
@@ -1537,6 +1540,9 @@ class _CompareMixin(ColumnOperators):
return self.__compare(op, ClauseList(*args).self_group(against=op), negate=negate_op)
+ def __neg__(self):
+ return _UnaryExpression(self, operator=operators.neg)
+
def startswith(self, other, escape=None):
"""Produce the clause ``LIKE '<other>%'``"""
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index 879f0f3e5..6f70b1778 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -4,7 +4,7 @@
"""Defines operators used in SQL expressions."""
from operator import (
- and_, or_, inv, add, mul, sub, mod, truediv, lt, le, ne, gt, ge, eq
+ and_, or_, inv, add, mul, sub, mod, truediv, lt, le, ne, gt, ge, eq, neg
)
# Py2K
@@ -98,6 +98,7 @@ _PRECEDENCE = {
div: 7,
# end Py2K
mod: 7,
+ neg: 7,
add: 6,
sub: 6,
concat_op: 6,