]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Preserve type for math negation
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 Jul 2016 16:44:47 +0000 (12:44 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 Jul 2016 16:44:47 +0000 (12:44 -0400)
Fixed issue in SQL math negation operator where the type of the
expression would no longer be the numeric type of the original.
This would cause issues where the type determined result set
behaviors.

Change-Id: If0e339614a3686e251235fc94b6f59310c4630a5
Fixes: #3735
doc/build/changelog/changelog_10.rst
lib/sqlalchemy/sql/default_comparator.py
test/sql/test_operators.py

index defee6d06e0cbc23cd2d2abdca7ac02111be1ae5..8a6b6b370326552065e1571aac7496160e682ec3 100644 (file)
 .. changelog::
     :version: 1.0.14
 
+    .. change::
+        :tags: bug, sql
+        :tickets: 3735
+
+        Fixed issue in SQL math negation operator where the type of the
+        expression would no longer be the numeric type of the original.
+        This would cause issues where the type determined result set
+        behaviors.
+
     .. change::
         :tags: bug, sql
         :tickets: 3728
index 7630a9821c07cc62b731cd1184a22a12edd70911..827492f10b6538a1d9774dbf398efea2a387f064 100644 (file)
@@ -192,7 +192,7 @@ def _inv_impl(expr, op, **kw):
 
 def _neg_impl(expr, op, **kw):
     """See :meth:`.ColumnOperators.__neg__`."""
-    return UnaryExpression(expr, operator=operators.neg)
+    return UnaryExpression(expr, operator=operators.neg, type_=expr.type)
 
 
 def _match_impl(expr, op, other, **kw):
index 5712d8f99e04e2b88579864a1a6f41f72ff4d44e..b6e80de4bad82d8f72c80d8c1f71e299abb09615 100644 (file)
@@ -1999,6 +1999,12 @@ class NegationTest(fixtures.TestBase, testing.AssertsCompiledSQL):
             "SELECT mytable.myid, mytable.name FROM "
             "mytable WHERE mytable.myid != :myid_1 AND NOT mytable.name")
 
+    def test_negate_operator_type(self):
+        is_(
+            (-self.table1.c.myid).type,
+            self.table1.c.myid.type,
+        )
+
 
 class LikeTest(fixtures.TestBase, testing.AssertsCompiledSQL):
     __dialect__ = 'default'