]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
gambit's patch to add DISTINCT ON
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 May 2006 21:30:41 +0000 (21:30 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 May 2006 21:30:41 +0000 (21:30 +0000)
lib/sqlalchemy/databases/postgres.py

index 19a703c0ce41a144e99817eb458b0055a8dac9e0..a92cb340dba7da344009c13245b436d033c1947c 100644 (file)
@@ -309,6 +309,20 @@ class PGCompiler(ansisql.ANSICompiler):
             text += " OFFSET " + str(select.offset)
         return text
 
+    def visit_select_precolumns(self, select):
+        if select.distinct:
+            if type(select.distinct) == bool:
+                return "DISTINCT "
+            if type(select.distinct) == list:
+                dist_set = "DISTINCT ON ("
+                for col in select.distinct:
+                    dist_set += self.strings[col] + ", "
+                    dist_set = dist_set[:-2] + ") "
+                return dist_set
+            return "DISTINCT ON (" + str(select.distinct) + ") "
+        else:
+            return ""
+             
     def binary_operator_string(self, binary):
         if isinstance(binary.type, sqltypes.String) and binary.operator == '+':
             return '||'