diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-01-01 21:17:49 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2021-01-01 21:17:49 +0000 |
| commit | 0d7f4c63669a0c43bf726d733c69f7aca6407f81 (patch) | |
| tree | a877649141df86772ae26e6c3b7cfe01e0558e61 /lib/sqlalchemy/dialects | |
| parent | 2581655c545a0cf705e0347e81cd092896d3207c (diff) | |
| parent | 95d8f401839bdbe1399fb7d656c11024072f32b0 (diff) | |
| download | sqlalchemy-0d7f4c63669a0c43bf726d733c69f7aca6407f81.tar.gz | |
Merge "Support casting to ``FLOAT`` in MySQL and MariaDb."
Diffstat (limited to 'lib/sqlalchemy/dialects')
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 7a4d3261f..a4b583541 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1624,6 +1624,11 @@ class MySQLCompiler(compiler.SQLCompiler): return self.dialect.type_compiler.process(type_).replace( "NUMERIC", "DECIMAL" ) + elif ( + isinstance(type_, sqltypes.Float) + and self.dialect._support_float_cast + ): + return self.dialect.type_compiler.process(type_) else: return None @@ -1631,7 +1636,7 @@ class MySQLCompiler(compiler.SQLCompiler): type_ = self.process(cast.typeclause) if type_ is None: util.warn( - "Datatype %s does not support CAST on MySQL; " + "Datatype %s does not support CAST on MySQL/MariaDb; " "the CAST will be skipped." % self.dialect.type_compiler.process(cast.typeclause.type) ) @@ -2900,6 +2905,17 @@ class MySQLDialect(default.DefaultDialect): ) @property + def _support_float_cast(self): + if not self.server_version_info: + return False + elif self.is_mariadb: + # ref https://mariadb.com/kb/en/mariadb-1045-release-notes/ + return self.server_version_info >= (10, 4, 5) + else: + # ref https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-17.html#mysqld-8-0-17-feature # noqa + return self.server_version_info >= (8, 0, 17) + + @property def _is_mariadb(self): return self.is_mariadb |
