From: Mike Bayer Date: Sun, 25 May 2014 18:08:41 +0000 (-0400) Subject: - Fixed bug in INSERT..FROM SELECT construct where selecting from a X-Git-Tag: rel_0_8_7~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=83b2e9e8d250a7e27d68c9071ad493222b1fdb09;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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 --- diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index c21420b7d6..8b00ce1faa 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -11,6 +11,14 @@ .. 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 diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index fadd8dde3c..444f412e5f 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -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 diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py index 8a5c7cd83b..d9f7b16292 100644 --- a/test/sql/test_insert.py +++ b/test/sql/test_insert.py @@ -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