]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Fix issues with JSON and float/numeric
authorGord Thompson <gord@gordthompson.com>
Sun, 20 Dec 2020 17:20:10 +0000 (10:20 -0700)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 21 Dec 2020 04:18:04 +0000 (23:18 -0500)
commit3b8a14153da9e7b6694571fa10f6d30c4012ee82
tree89c26616a9088bad7c9c0c195fa96fcc24b5fe13
parenta8f51f3c11f3cb2e344732cf3abb371f03ed30d8
Fix issues with JSON and float/numeric

Decimal accuracy and behavior has been improved when extracting floating
point and/or decimal values from JSON strings using the
:meth:`_sql.sqltypes.JSON.Comparator.as_float` method, when the numeric
value inside of the JSON string has many significant digits; previously,
MySQL backends would truncate values with many significant digits and SQL
Server backends would raise an exception due to a DECIMAL cast with
insufficient significant digits.   Both backends now use a FLOAT-compatible
approach that does not hardcode significant digits for floating point
values. For precision numerics, a new method
:meth:`_sql.sqltypes.JSON.Comparator.as_numeric` has been added which
accepts arguments for precision and scale, and will return values as Python
``Decimal`` objects with no floating point conversion assuming the DBAPI
supports it (all but pysqlite).

Fixes: #5788
Change-Id: I6eb51fe172a389548dd6e3c65efec9f1f538012e
doc/build/changelog/unreleased_14/5788.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/sql/sqltypes.py
lib/sqlalchemy/testing/requirements.py
lib/sqlalchemy/testing/suite/test_types.py
test/requirements.py