insert from select column ordering

Issue #2895 resolved
Mike Bayer repo owner created an issue
diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py
index e117153..22c6147 100644
--- a/test/sql/test_insert.py
+++ b/test/sql/test_insert.py
@@ -133,6 +133,20 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL):
             checkparams={"name_1": "foo"}
         )

+
+    def test_insert_from_select_select_alt_ordering(self):
+        table1 = self.tables.mytable
+        sel = select([table1.c.myid, ](table1.c.name,)).where(table1.c.name == 'foo')
+        ins = self.tables.myothertable.insert().\
+                    from_select(("othername", "otherid"), sel)
+        self.assert_compile(
+            ins,
+            "INSERT INTO myothertable (otherid, othername) "
+            "SELECT mytable.myid, mytable.name FROM mytable "
+            "WHERE mytable.name = :name_1",
+            checkparams={"name_1": "foo"}
+        )
+
     def test_insert_mix_select_values_exception(self):
         table1 = self.tables.mytable
         sel = select([table1.c.name](table1.c.myid,)).where(table1.c.name == 'foo')

current output is:

INSERT INTO myothertable (otherid, othername) SELECT mytable.name, mytable.myid FROM mytable WHERE mytable.name = :name_1

Comments (2)

  1. Log in to comment