From: Mike Bayer Date: Wed, 2 Apr 2014 22:11:11 +0000 (-0400) Subject: - reverse order of columns in sample CTEs as this is a UNION and the cols need to... X-Git-Tag: rel_0_8_7~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df7fe021a945287edc500cd9983258eec4a1970c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - reverse order of columns in sample CTEs as this is a UNION and the cols need to line up - alter this in the unit tests as well as these queries were just copied from the tests - remove the included_parts.join(parts) from the core CTE doc (also just copied from the test, where we want to make sure joins don't get screwed up with the CTE) as it doesn't contribute to the query itself fixes #3014 --- diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 3bd6add8f1..e604e2dc70 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -530,8 +530,8 @@ class Query(object): parts_alias = aliased(Part, name="p") included_parts = included_parts.union_all( session.query( - parts_alias.part, parts_alias.sub_part, + parts_alias.part, parts_alias.quantity).\\ filter(parts_alias.part==incl_alias.c.sub_part) ) diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index b60d6d343e..fadd8dde3c 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -5535,8 +5535,8 @@ class SelectBase(Executable, FromClause): parts_alias = parts.alias() included_parts = included_parts.union_all( select([ - parts_alias.c.part, parts_alias.c.sub_part, + parts_alias.c.part, parts_alias.c.quantity ]). where(parts_alias.c.part==incl_alias.c.sub_part) @@ -5546,9 +5546,7 @@ class SelectBase(Executable, FromClause): included_parts.c.sub_part, func.sum(included_parts.c.quantity). label('total_quantity') - ]).\ - select_from(included_parts.join(parts, - included_parts.c.part==parts.c.part)).\\ + ]).\\ group_by(included_parts.c.sub_part) result = conn.execute(statement).fetchall() diff --git a/test/sql/test_cte.py b/test/sql/test_cte.py index 0f68313759..887d567107 100644 --- a/test/sql/test_cte.py +++ b/test/sql/test_cte.py @@ -77,8 +77,8 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): parts_alias = parts.alias() included_parts = included_parts.union( select([ - parts_alias.c.part, parts_alias.c.sub_part, + parts_alias.c.part, parts_alias.c.quantity]).\ where(parts_alias.c.part==incl_alias.c.sub_part) ) @@ -93,8 +93,8 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): "WITH RECURSIVE anon_1(sub_part, part, quantity) " "AS (SELECT parts.sub_part AS sub_part, parts.part " "AS part, parts.quantity AS quantity FROM parts " - "WHERE parts.part = :part_1 UNION SELECT parts_1.part " - "AS part, parts_1.sub_part AS sub_part, parts_1.quantity " + "WHERE parts.part = :part_1 UNION SELECT parts_1.sub_part AS sub_part, " + "parts_1.part AS part, parts_1.quantity " "AS quantity FROM parts AS parts_1, anon_1 AS anon_2 " "WHERE parts_1.part = anon_2.sub_part) " "SELECT anon_1.sub_part, " @@ -109,8 +109,8 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): "WITH anon_1(sub_part, part, quantity) " "AS (SELECT parts.sub_part AS sub_part, parts.part " "AS part, parts.quantity AS quantity FROM parts " - "WHERE parts.part = :part_1 UNION SELECT parts_1.part " - "AS part, parts_1.sub_part AS sub_part, parts_1.quantity " + "WHERE parts.part = :part_1 UNION SELECT parts_1.sub_part AS sub_part, " + "parts_1.part AS part, parts_1.quantity " "AS quantity FROM parts AS parts_1, anon_1 AS anon_2 " "WHERE parts_1.part = anon_2.sub_part) " "SELECT anon_1.sub_part, "