From cec89cae156903c9a77dff29a1213e70fa915b52 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 5 Jul 2013 15:51:24 -0400 Subject: - Added new method to the :func:`.insert` construct :meth:`.Insert.from_select`. Given a list of columns and a selectable, renders ``INSERT INTO (table) (columns) SELECT ..``. While this feature is highlighted as part of 0.9 it is also backported to 0.8.3. [ticket:722] - The :func:`.update`, :func:`.insert`, and :func:`.delete` constructs will now interpret ORM entities as FROM clauses to be operated upon, in the same way that select() already does. Also in 0.8.3. --- lib/sqlalchemy/testing/suite/test_insert.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/sqlalchemy/testing/suite/test_insert.py') diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py index a00fde312..ef05291b5 100644 --- a/lib/sqlalchemy/testing/suite/test_insert.py +++ b/lib/sqlalchemy/testing/suite/test_insert.py @@ -121,6 +121,34 @@ class InsertBehaviorTest(fixtures.TablesTest): assert len(r.fetchall()) + @requirements.insert_from_select + def test_insert_from_select(self): + table = self.tables.autoinc_pk + config.db.execute( + table.insert(), + [ + dict(data="data1"), + dict(data="data2"), + dict(data="data3"), + ] + ) + + + config.db.execute( + table.insert(). + from_select( + ("data",), select([table.c.data]).where( + table.c.data.in_(["data2", "data3"])) + ), + ) + + eq_( + config.db.execute( + select([table.c.data]).order_by(table.c.data) + ).fetchall(), + [("data1", ), ("data2", ), ("data2", ), + ("data3", ), ("data3", )] + ) class ReturningTest(fixtures.TablesTest): run_deletes = 'each' -- cgit v1.2.1