From: Mike Bayer Date: Wed, 22 Aug 2018 21:18:48 +0000 (-0400) Subject: Propagate **kw in postgresql distinct on compilation X-Git-Tag: rel_1_3_0b1~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=469931514a1517dde82ba56f780c3007c66d5943;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Propagate **kw in postgresql distinct on compilation Fixed bug in PostgreSQL dialect where compiler keyword arguments such as ``literal_binds=True`` were not being propagated to a DISTINCT ON expression. Fixes: #4325 Change-Id: I9949387dceb7fabe889799f42e92423572368b29 --- diff --git a/doc/build/changelog/unreleased_12/4325.rst b/doc/build/changelog/unreleased_12/4325.rst new file mode 100644 index 0000000000..9d6f38ef87 --- /dev/null +++ b/doc/build/changelog/unreleased_12/4325.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, postgresql + :tickets: 4325 + + Fixed bug in PostgreSQL dialect where compiler keyword arguments such as + ``literal_binds=True`` were not being propagated to a DISTINCT ON + expression. diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 7db26e4c0c..ea2c518709 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1525,7 +1525,7 @@ class PGCompiler(compiler.SQLCompiler): return "DISTINCT " elif isinstance(select._distinct, (list, tuple)): return "DISTINCT ON (" + ', '.join( - [self.process(col) for col in select._distinct] + [self.process(col, **kw) for col in select._distinct] ) + ") " else: return "DISTINCT ON (" + \ diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py index 5c4d72c670..6133ab4821 100644 --- a/test/dialect/postgresql/test_compiler.py +++ b/test/dialect/postgresql/test_compiler.py @@ -1571,6 +1571,13 @@ class DistinctOnTest(fixtures.TestBase, AssertsCompiledSQL): "SELECT DISTINCT ON (t.a) t.id, t.a, t.b FROM t" ) + def test_literal_binds(self): + self.assert_compile( + select([self.table]).distinct(self.table.c.a == 10), + "SELECT DISTINCT ON (t.a = 10) t.id, t.a, t.b FROM t", + literal_binds=True + ) + def test_query_plain(self): sess = Session() self.assert_compile(