summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--lib/sqlalchemy/types.py5
-rw-r--r--test/sql/test_types.py24
3 files changed, 34 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 24bd97b28..da9f3dca0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -77,6 +77,11 @@ CHANGES
the outer query. [ticket:1852]
- sql
+ - Added basic math expression coercion for
+ Numeric->Integer,
+ so that resulting type is Numeric regardless
+ of the direction of the expression.
+
- Changed the scheme used to generate truncated
"auto" index names when using the "index=True"
flag on Column. The truncation only takes
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 91eb35275..777353714 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -1024,20 +1024,25 @@ class Numeric(_DateAffinity, TypeEngine):
operators.mul:{
Interval:Interval,
Numeric:Numeric,
+ Integer:Numeric,
},
# Py2K
operators.div:{
Numeric:Numeric,
+ Integer:Numeric,
},
# end Py2K
operators.truediv:{
Numeric:Numeric,
+ Integer:Numeric,
},
operators.add:{
Numeric:Numeric,
+ Integer:Numeric,
},
operators.sub:{
Numeric:Numeric,
+ Integer:Numeric,
}
}
diff --git a/test/sql/test_types.py b/test/sql/test_types.py
index 91e4ec177..a80e761d7 100644
--- a/test/sql/test_types.py
+++ b/test/sql/test_types.py
@@ -904,6 +904,30 @@ class ExpressionTest(TestBase, AssertsExecutionResults, AssertsCompiledSQL):
expr = func.current_date() - column('foo', types.TIMESTAMP)
eq_(expr.type._type_affinity, types.Interval)
+ def test_numerics_coercion(self):
+ from sqlalchemy.sql import column
+ import operator
+
+ for op in (
+ operator.add,
+ operator.mul,
+ operator.truediv,
+ operator.sub
+ ):
+ for other in (Numeric(10, 2), Integer):
+ expr = op(
+ column('bar', types.Numeric(10, 2)),
+ column('foo', other)
+ )
+ assert isinstance(expr.type, types.Numeric)
+ expr = op(
+ column('foo', other),
+ column('bar', types.Numeric(10, 2))
+ )
+ assert isinstance(expr.type, types.Numeric)
+
+
+
def test_expression_typing(self):
expr = column('bar', Integer) - 3