.. 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
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
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