From bc0367c670cc1376b90ab2309085bd660ec317c9 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 10 Jun 2022 12:57:53 -0400 Subject: resolve large ints to BigInteger The in-place type detection for Python integers, as occurs with an expression such as ``literal(25)``, will now apply value-based adaption as well to accommodate Python large integers, where the datatype determined will be :class:`.BigInteger` rather than :class:`.Integer`. This accommodates for dialects such as that of asyncpg which both sends implicit typing information to the driver as well as is sensitive to numeric scale. Fixes: #7909 Change-Id: I1cd3ec2676c9bb03ffedb600695252bd0037ba02 --- lib/sqlalchemy/sql/sqltypes.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 50cb32503..2cc46107b 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -366,6 +366,12 @@ class Integer(HasExpressionLookup, TypeEngine[int]): def python_type(self): return int + def _resolve_for_literal(self, value): + if value.bit_length() >= 32: + return _BIGINTEGER + else: + return self + def literal_processor(self, dialect): def process(value): return str(int(value)) @@ -3556,6 +3562,7 @@ MATCHTYPE = MatchType() TABLEVALUE = TableValueType() DATETIME_TIMEZONE = DateTime(timezone=True) TIME_TIMEZONE = Time(timezone=True) +_BIGINTEGER = BigInteger() _DATETIME = DateTime() _TIME = Time() _STRING = String() -- cgit v1.2.1