]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- reverse order of columns in sample CTEs as this is a UNION and the cols need to...
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Apr 2014 22:11:11 +0000 (18:11 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Apr 2014 22:13:52 +0000 (18:13 -0400)
- 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

lib/sqlalchemy/orm/query.py
lib/sqlalchemy/sql/expression.py
test/sql/test_cte.py

index 3bd6add8f126fcaa676c441c2367a0b68f5615b8..e604e2dc700284484cf7f5b1e243b6319881af71 100644 (file)
@@ -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)
                 )
index b60d6d343e93b7784aaa25e13c34d6dafb1e5eb2..fadd8dde3cd99b028e61c5baea12fd8350201fc2 100644 (file)
@@ -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()
index 0f68313759f830391619989065c6bec77f027473..887d567107b7b15fbde835237659b6f57ee3d9d2 100644 (file)
@@ -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, "