From 62b7a8133a54a07934153b767a7f755a28beec24 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 30 Sep 2012 17:18:14 -0400 Subject: - [bug] Fixed bug in over() construct whereby passing an empty list for either partition_by or order_by, as opposed to None, would fail to generate correctly. Courtesy Gunnlaugur Por Briem. [ticket:2574] --- lib/sqlalchemy/sql/compiler.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/sqlalchemy/sql/compiler.py') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 3b17c040c..d97c048a9 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -530,17 +530,17 @@ class SQLCompiler(engine.Compiled): cast.typeclause._compiler_dispatch(self, **kwargs)) def visit_over(self, over, **kwargs): - x = "%s OVER (" % over.func._compiler_dispatch(self, **kwargs) - if over.partition_by is not None: - x += "PARTITION BY %s" % \ - over.partition_by._compiler_dispatch(self, **kwargs) - if over.order_by is not None: - x += " " - if over.order_by is not None: - x += "ORDER BY %s" % \ - over.order_by._compiler_dispatch(self, **kwargs) - x += ")" - return x + return "%s OVER (%s)" % ( + over.func._compiler_dispatch(self, **kwargs), + ' '.join( + '%s BY %s' % (word, clause._compiler_dispatch(self, **kwargs)) + for word, clause in ( + ('PARTITION', over.partition_by), + ('ORDER', over.order_by) + ) + if clause is not None and len(clause) + ) + ) def visit_extract(self, extract, **kwargs): field = self.extract_map.get(extract.field, extract.field) -- cgit v1.2.1