Commits

Mike Bayer committed 076eef5

- Fixed bug in INSERT..FROM SELECT construct where selecting from a
UNION would wrap the union in an anonymous (e.g. unlabled) subquery.
fixes #3044

  • Participants
  • Parent commits 64e887b
  • Branches rel_0_9

Comments (0)

Files changed (3)

doc/build/changelog/changelog_08.rst

     :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
         :tickets: 3053

lib/sqlalchemy/sql/selectable.py

     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
 

test/sql/test_insert.py

             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