diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2020-04-16 23:16:32 +0200 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-04-20 11:28:51 -0400 |
| commit | 07d6d211f23f1d9d1d69fd54e8054bccd515bc8c (patch) | |
| tree | 321a19e49f8918ec38bba96bf4c062633801bd26 /lib/sqlalchemy/dialects | |
| parent | 2f617f56f2acdce00b88f746c403cf5ed66d4d27 (diff) | |
| download | sqlalchemy-07d6d211f23f1d9d1d69fd54e8054bccd515bc8c.tar.gz | |
Deprecate ``DISTINCT ON`` when not targeting PostgreSQL
Deprecate usage of ``DISTINCT ON`` in dialect other than PostgreSQL.
Previously this was silently ignored.
Deprecate old usage of string distinct in MySQL dialect
Fixes: #4002
Change-Id: I38fc64aef75e77748083c11d388ec831f161c9c9
Diffstat (limited to 'lib/sqlalchemy/dialects')
| -rw-r--r-- | lib/sqlalchemy/dialects/firebird/base.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 12 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/mysql/base.py | 21 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 2 |
4 files changed, 18 insertions, 20 deletions
diff --git a/lib/sqlalchemy/dialects/firebird/base.py b/lib/sqlalchemy/dialects/firebird/base.py index a43413780..5779ac885 100644 --- a/lib/sqlalchemy/dialects/firebird/base.py +++ b/lib/sqlalchemy/dialects/firebird/base.py @@ -525,8 +525,7 @@ class FBCompiler(sql.compiler.SQLCompiler): result += "FIRST %s " % self.process(select._limit_clause, **kw) if select._offset_clause is not None: result += "SKIP %s " % self.process(select._offset_clause, **kw) - if select._distinct: - result += "DISTINCT " + result += super(FBCompiler, self).get_select_precolumns(select, **kw) return result def limit_clause(self, select, **kw): diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index df6196bae..0dd2ac11b 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -1636,9 +1636,7 @@ class MSSQLCompiler(compiler.SQLCompiler): def get_select_precolumns(self, select, **kw): """ MS-SQL puts TOP, it's version of LIMIT here """ - s = "" - if select._distinct: - s += "DISTINCT " + s = super(MSSQLCompiler, self).get_select_precolumns(select, **kw) if select._simple_int_limit and ( select._offset_clause is None @@ -1649,12 +1647,8 @@ class MSSQLCompiler(compiler.SQLCompiler): # so have to use literal here. kw["literal_execute"] = True s += "TOP %s " % self.process(select._limit_clause, **kw) - if s: - return s - else: - return compiler.SQLCompiler.get_select_precolumns( - self, select, **kw - ) + + return s def get_from_hint_text(self, table, text): return text diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 53c916304..38f3fa611 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1450,19 +1450,22 @@ class MySQLCompiler(compiler.SQLCompiler): def get_select_precolumns(self, select, **kw): """Add special MySQL keywords in place of DISTINCT. - .. note:: - - this usage is deprecated. :meth:`_expression.Select.prefix_with` - should be used for special keywords at the start - of a SELECT. + .. deprecated 1.4:: this usage is deprecated. + :meth:`_expression.Select.prefix_with` should be used for special + keywords at the start of a SELECT. """ if isinstance(select._distinct, util.string_types): + util.warn_deprecated( + "Sending string values for 'distinct' is deprecated in the " + "MySQL dialect and will be removed in a future release. " + "Please use :meth:`.Select.prefix_with` for special keywords " + "at the start of a SELECT statement", + version="1.4", + ) return select._distinct.upper() + " " - elif select._distinct: - return "DISTINCT " - else: - return "" + + return super(MySQLCompiler, self).get_select_precolumns(select, **kw) def visit_join(self, join, asfrom=False, from_linter=None, **kwargs): if from_linter: diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 20540ac02..ca2f6a8a4 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1693,6 +1693,8 @@ class PGCompiler(compiler.SQLCompiler): return "ONLY " + sqltext def get_select_precolumns(self, select, **kw): + # Do not call super().get_select_precolumns because + # it will warn/raise when distinct on is present if select._distinct or select._distinct_on: if select._distinct_on: return ( |
