]> 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:11:11 +0000 (18:11 -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/selectable.py
test/sql/test_cte.py

index 827fdb5becb2d302d0ccc73ddd676ea2f74ce1c1..5d60c4e29dfdcf494ec07d65b77b8dc87c9c1fe3 100644 (file)
@@ -519,8 +519,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 cfa229f940a1507b0f9b6beacbee8596ee11e39e..2aa2c0f405bbe6a6f0682f116b7dc94b57a7cbc8 100644 (file)
@@ -1467,8 +1467,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)
@@ -1479,8 +1479,6 @@ class SelectBase(Executable, FromClause):
                         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, "