]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug in INSERT..FROM SELECT construct where selecting from a
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 May 2014 18:08:41 +0000 (14:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 25 May 2014 18:10:34 +0000 (14:10 -0400)
UNION would wrap the union in an anonymous (e.g. unlabled) subquery.
fixes #3044

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/sql/expression.py
test/sql/test_insert.py

index c21420b7d6410c4260db3a0ef658b87e8c713e9b..8b00ce1faa780305412ebf1fbd05d24da514b28f 100644 (file)
 .. changelog::
     :version: 0.8.7
 
+    .. change::
+        :tags: bug, sql
+        :versions: 0.9.5, 1.0.0
+        :tickets: 3044
+
+        Fixed bug in INSERT..FROM SELECT construct where selecting from a
+        UNION would wrap the union in an anonymous (e.g. unlabled) subquery.
+
     .. change::
         :tags: bug, postgresql
         :versions: 0.9.5, 1.0.0
index fadd8dde3cd99b028e61c5baea12fd8350201fc2..444f412e5f026c205680e22ac36a95e8907d346a 100644 (file)
@@ -2108,7 +2108,7 @@ def _interpret_as_select(element):
     element = _interpret_as_from(element)
     if isinstance(element, Alias):
         element = element.original
-    if not isinstance(element, Select):
+    if not isinstance(element, SelectBase):
         element = element.select()
     return element
 
index 8a5c7cd83b4fc165897951a1198070c4991083fc..d9f7b16292f7bfda724ffcacbfab2f18bee9a751 100644 (file)
@@ -196,7 +196,25 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
             checkparams={}
         )
 
-
+    def test_insert_from_select_union(self):
+        mytable = self.tables.mytable
+
+        name = 'name'
+        description = 'desc'
+        sel = select(
+            [name, mytable.c.description],
+        ).union(
+            select([name, description])
+        )
+        ins = mytable.insert().\
+                    from_select(
+                            [mytable.c.name, mytable.c.description], sel)
+        self.assert_compile(
+            ins,
+            "INSERT INTO mytable (name, description) "
+                    "SELECT name, mytable.description FROM mytable "
+                    "UNION SELECT name, desc"
+        )
     def test_insert_from_select_col_values(self):
         table1 = self.tables.mytable
         table2 = self.tables.myothertable