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/testing | |
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/testing')
-rw-r--r-- | lib/sqlalchemy/testing/assertions.py | 1 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/requirements.py | 5 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_select.py | 15 |
3 files changed, 20 insertions, 1 deletions
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py index 61d272160..05dcf230b 100644 --- a/lib/sqlalchemy/testing/assertions.py +++ b/lib/sqlalchemy/testing/assertions.py @@ -412,7 +412,6 @@ class AssertsCompiledSQL(object): c = clause.compile(dialect=dialect, **kw) param_str = repr(getattr(c, "params", {})) - if util.py3k: param_str = param_str.encode("utf-8").decode("ascii", "ignore") print( diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index 644483b79..31011a970 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -1170,6 +1170,11 @@ class SuiteRequirements(Requirements): return exclusions.closed() @property + def supports_distinct_on(self): + """If a backend supports the DISTINCT ON in a select""" + return exclusions.closed() + + @property def supports_is_distinct_from(self): """Supports some form of "x IS [NOT] DISTINCT FROM y" construct. Different dialects will implement their own flavour, e.g., diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py index c1f77a7c1..ad17ebb4a 100644 --- a/lib/sqlalchemy/testing/suite/test_select.py +++ b/lib/sqlalchemy/testing/suite/test_select.py @@ -12,6 +12,7 @@ from ..schema import Column from ..schema import Table from ... import bindparam from ... import case +from ... import column from ... import Computed from ... import false from ... import func @@ -20,6 +21,7 @@ from ... import literal_column from ... import null from ... import select from ... import String +from ... import table from ... import testing from ... import text from ... import true @@ -1016,6 +1018,19 @@ class ComputedColumnTest(fixtures.TablesTest): eq_(res, [(100, 40), (1764, 168)]) +class DistinctOnTest(AssertsCompiledSQL, fixtures.TablesTest): + __backend__ = True + __requires__ = ("standard_cursor_sql",) + + @testing.fails_if(testing.requires.supports_distinct_on) + def test_distinct_on(self): + stm = select(["*"]).distinct(column("q")).select_from(table("foo")) + with testing.expect_deprecated( + "DISTINCT ON is currently supported only by the PostgreSQL " + ): + self.assert_compile(stm, "SELECT DISTINCT * FROM foo") + + class IsOrIsNotDistinctFromTest(fixtures.TablesTest): __backend__ = True __requires__ = ("supports_is_distinct_from",) |