Fixed bug where "distinct" keyword passed to :func:`.select` would not
treat a string value as a "label reference" in the same way that the
:meth:`.select.distinct` does; it would instead raise unconditionally. This
keyword argument and the others passed to :func:`.select` will ultimately
be deprecated for SQLAlchemy 2.0.
Fixes: #5028
Change-Id: Id36cfe477ed836c3248824ce1b81d0016dbe99f4
--- /dev/null
+.. change::
+ :tags: bug, sql
+ :tickets: 5028
+
+ Fixed bug where "distinct" keyword passed to :func:`.select` would not
+ treat a string value as a "label reference" in the same way that the
+ :meth:`.select.distinct` does; it would instead raise unconditionally. This
+ keyword argument and the others passed to :func:`.select` will ultimately
+ be deprecated for SQLAlchemy 2.0.
+
if not isinstance(distinct, bool):
self._distinct_on = tuple(
[
- coercions.expect(roles.WhereHavingRole, e)
+ coercions.expect(roles.ByOfRole, e)
for e in util.to_list(distinct)
]
)
dialect="postgresql",
)
+ def test_distinct_label_keyword(self):
+
+ stmt = select([table1.c.myid.label("foo")], distinct="foo")
+ self.assert_compile(
+ stmt,
+ "SELECT DISTINCT ON (foo) mytable.myid AS foo FROM mytable",
+ dialect="postgresql",
+ )
+
def test_unresolvable_distinct_label(self):
from sqlalchemy.dialects import postgresql