]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Propagate **kw in postgresql distinct on compilation
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 22 Aug 2018 21:18:48 +0000 (17:18 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 22 Aug 2018 21:19:45 +0000 (17:19 -0400)
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

doc/build/changelog/unreleased_12/4325.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_compiler.py

diff --git a/doc/build/changelog/unreleased_12/4325.rst b/doc/build/changelog/unreleased_12/4325.rst
new file mode 100644 (file)
index 0000000..9d6f38e
--- /dev/null
@@ -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.
index 7db26e4c0c36d0c48c97c5ae481883fe4beeee72..ea2c5187092da6b3ad4c9e7a0641cc1624440229 100644 (file)
@@ -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 (" + \
index 5c4d72c6703220a683701ffb9ff31e4b011557cc..6133ab4821680eead771adae2f8350ff1cd14d22 100644 (file)
@@ -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(