summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/changelog_10.rst9
-rw-r--r--lib/sqlalchemy/sql/default_comparator.py2
-rw-r--r--test/sql/test_operators.py6
3 files changed, 16 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_10.rst b/doc/build/changelog/changelog_10.rst
index defee6d06..8a6b6b370 100644
--- a/doc/build/changelog/changelog_10.rst
+++ b/doc/build/changelog/changelog_10.rst
@@ -20,6 +20,15 @@
.. 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
Fixed bug whereby the ``__getstate__`` / ``__setstate__``
diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py
index 7630a9821..827492f10 100644
--- a/lib/sqlalchemy/sql/default_comparator.py
+++ b/lib/sqlalchemy/sql/default_comparator.py
@@ -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):
diff --git a/test/sql/test_operators.py b/test/sql/test_operators.py
index 5712d8f99..b6e80de4b 100644
--- a/test/sql/test_operators.py
+++ b/test/sql/test_operators.py
@@ -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'