summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-04-16 23:16:32 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2020-04-20 11:28:51 -0400
commit07d6d211f23f1d9d1d69fd54e8054bccd515bc8c (patch)
tree321a19e49f8918ec38bba96bf4c062633801bd26 /lib/sqlalchemy/sql
parent2f617f56f2acdce00b88f746c403cf5ed66d4d27 (diff)
downloadsqlalchemy-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/sql')
-rw-r--r--lib/sqlalchemy/sql/compiler.py11
-rw-r--r--lib/sqlalchemy/sql/selectable.py3
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index bc16b1429..23eff773c 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -2868,7 +2868,16 @@ class SQLCompiler(Compiled):
before column list.
"""
- return select._distinct and "DISTINCT " or ""
+ if select._distinct_on:
+ util.warn_deprecated(
+ "DISTINCT ON is currently supported only by the PostgreSQL "
+ "dialect. Use of DISTINCT ON for other backends is currently "
+ "silently ignored, however this usage is deprecated, and will "
+ "raise CompileError in a future release for all backends "
+ "that do not support this syntax.",
+ version="1.4",
+ )
+ return "DISTINCT " if select._distinct else ""
def group_by_clause(self, select, **kw):
"""allow dialects to customize how GROUP BY is rendered."""
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index 89ee7e28f..c8df637ba 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -4138,6 +4138,9 @@ class Select(
the PostgreSQL dialect will render a ``DISTINCT ON (<expressions>>)``
construct.
+ .. deprecated:: 1.4 Using \*expr in other dialects is deprecated
+ and will raise :class:`_exc.CompileError` in a future version.
+
"""
if expr:
self._distinct = True