]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add test for [ticket:2142]
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 23 Apr 2011 19:05:50 +0000 (15:05 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 23 Apr 2011 19:05:50 +0000 (15:05 -0400)
test/dialect/test_postgresql.py

index de71695793cecffca845b638e439a804a8db1023..125b590f1d24811c0bf575620a4cdf81414d391c 100644 (file)
@@ -1203,6 +1203,33 @@ class DistinctOnTest(fixtures.TestBase, AssertsCompiledSQL):
             "t_1.a AS t_1_a, t_1.b AS t_1_b FROM t AS t_1"
         )
 
+    def test_distinct_on_subquery_anon(self):
+
+        sq = select([self.table]).alias()
+        q = select([self.table.c.id,sq.c.id]).\
+                    distinct(sq.c.id).\
+                    where(self.table.c.id==sq.c.id)
+
+        self.assert_compile(
+            q,
+            "SELECT DISTINCT ON (anon_1.id) t.id, anon_1.id "
+            "FROM t, (SELECT t.id AS id, t.a AS a, t.b "
+            "AS b FROM t) AS anon_1 WHERE t.id = anon_1.id"
+            )
+
+    def test_distinct_on_subquery_named(self):
+        sq = select([self.table]).alias('sq')
+        q = select([self.table.c.id,sq.c.id]).\
+                    distinct(sq.c.id).\
+                    where(self.table.c.id==sq.c.id)
+        self.assert_compile(
+            q,
+            "SELECT DISTINCT ON (sq.id) t.id, sq.id "
+            "FROM t, (SELECT t.id AS id, t.a AS a, "
+            "t.b AS b FROM t) AS sq WHERE t.id = sq.id"
+            )
+
+
 class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL):
 
     __only_on__ = 'postgresql'