From 509f3fb492a4be70842dde65f9b84a86671e857f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 17 Apr 2011 13:40:37 -0400 Subject: [PATCH] - Fixed incorrect usage of "," in over() clause being placed between the "partition" and "order by" clauses. [ticket:2134] --- CHANGES | 4 ++++ lib/sqlalchemy/sql/compiler.py | 2 +- test/sql/test_compiler.py | 13 +++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 16fe6200d5..3aaf6f85f2 100644 --- a/CHANGES +++ b/CHANGES @@ -96,6 +96,10 @@ CHANGES not a list, causing "can only concatenate list" TypeError when combined with other clauses. + - Fixed incorrect usage of "," in over() clause + being placed between the "partition" and "order by" + clauses. [ticket:2134] + - engine - The C extension is now enabled by default on CPython 2.x with a fallback to pure python if it fails to diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 7c409e0e63..fe04da1a1b 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -468,7 +468,7 @@ class SQLCompiler(engine.Compiled): x += "PARTITION BY %s" % \ over.partition_by._compiler_dispatch(self, **kwargs) if over.order_by is not None: - x += ", " + x += " " if over.order_by is not None: x += "ORDER BY %s" % \ over.order_by._compiler_dispatch(self, **kwargs) diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index abebb7b3ba..678411fe2c 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -2094,7 +2094,7 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): partition_by=[table1.c.name], order_by=[table1.c.description] ), - "row_number() OVER (PARTITION BY mytable.name, " + "row_number() OVER (PARTITION BY mytable.name " "ORDER BY mytable.description)" ) self.assert_compile( @@ -2102,10 +2102,19 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): partition_by=table1.c.name, order_by=table1.c.description ), - "row_number() OVER (PARTITION BY mytable.name, " + "row_number() OVER (PARTITION BY mytable.name " "ORDER BY mytable.description)" ) + self.assert_compile( + func.row_number().over( + partition_by=table1.c.name, + order_by=[table1.c.name, table1.c.description] + ), + "row_number() OVER (PARTITION BY mytable.name " + "ORDER BY mytable.name, mytable.description)" + ) + self.assert_compile( select([func.row_number().over( order_by=table1.c.description -- 2.39.5