]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
consider truediv as truediv; support floordiv operator
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Dec 2021 13:57:44 +0000 (08:57 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 27 Dec 2021 00:32:53 +0000 (19:32 -0500)
commit6d589ffbb5fe04a4ee606819e948974045f62b80
tree95fc3ac54ae23945e3bf810f85294193f4fbbd82
parent2bb6cfc7c9b8f09eaa4efeffc337a1162993979c
consider truediv as truediv; support floordiv operator

Implemented full support for "truediv" and "floordiv" using the
"/" and "//" operators.  A "truediv" operation between two expressions
using :class:`_types.Integer` now considers the result to be
:class:`_types.Numeric`, and the dialect-level compilation will cast
the right operand to a numeric type on a dialect-specific basis to ensure
truediv is achieved.  For floordiv, conversion is also added for those
databases that don't already do floordiv by default (MySQL, Oracle) and
the ``FLOOR()`` function is rendered in this case, as well as for
cases where the right operand is not an integer (needed for PostgreSQL,
others).

The change resolves issues both with inconsistent behavior of the
division operator on different backends and also fixes an issue where
integer division on Oracle would fail to be able to fetch a result due
to inappropriate outputtypehandlers.

Fixes: #4926
Change-Id: Id54cc018c1fb7a49dd3ce1216d68d40f43fe2659
20 files changed:
doc/build/changelog/migration_20.rst
doc/build/changelog/unreleased_20/4926.rst [new file with mode: 0644]
doc/build/core/operators.rst
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/oracle/base.py
lib/sqlalchemy/dialects/sqlite/base.py
lib/sqlalchemy/dialects/sqlite/pysqlite.py
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/default_comparator.py
lib/sqlalchemy/sql/operators.py
lib/sqlalchemy/sql/sqltypes.py
lib/sqlalchemy/testing/suite/test_types.py
test/dialect/oracle/test_types.py
test/dialect/postgresql/test_compiler.py
test/orm/test_query.py
test/sql/test_compiler.py
test/sql/test_cte.py
test/sql/test_operators.py
test/sql/test_selectable.py