summaryrefslogtreecommitdiff
path: root/test/sql/test_query.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-08-20 20:14:20 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-08-20 20:14:20 -0400
commit71ca494f518658676b532afaf84a4cc93025dbbb (patch)
tree7de7ba2791382d35a051b3f15474945f14b2890e /test/sql/test_query.py
parent89ff6df7dcdfa144efbd4d7c2031c0643a266351 (diff)
downloadsqlalchemy-71ca494f518658676b532afaf84a4cc93025dbbb.tar.gz
- The INSERT...FROM SELECT construct now implies ``inline=True``
on :class:`.Insert`. This helps to fix a bug where an INSERT...FROM SELECT construct would inadvertently be compiled as "implicit returning" on supporting backends, which would cause breakage in the case of an INSERT that inserts zero rows (as implicit returning expects a row), as well as arbitrary return data in the case of an INSERT that inserts multiple rows (e.g. only the first row of many). A similar change is also applied to an INSERT..VALUES with multiple parameter sets; implicit RETURNING will no longer emit for this statement either. As both of these constructs deal with varible numbers of rows, the :attr:`.ResultProxy.inserted_primary_key` accessor does not apply. Previously, there was a documentation note that one may prefer ``inline=True`` with INSERT..FROM SELECT as some databases don't support returning and therefore can't do "implicit" returning, but there's no reason an INSERT...FROM SELECT needs implicit returning in any case. Regular explicit :meth:`.Insert.returning` should be used to return variable numbers of result rows if inserted data is needed. fixes #3169
Diffstat (limited to 'test/sql/test_query.py')
-rw-r--r--test/sql/test_query.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/test/sql/test_query.py b/test/sql/test_query.py
index a475b899f..2075bcecf 100644
--- a/test/sql/test_query.py
+++ b/test/sql/test_query.py
@@ -276,6 +276,13 @@ class QueryTest(fixtures.TestBase):
r = t6.insert().values(manual_id=id).execute()
eq_(r.inserted_primary_key, [12, 1])
+ def test_implicit_id_insert_select(self):
+ stmt = users.insert().from_select(
+ (users.c.user_id, users.c.user_name),
+ users.select().where(users.c.user_id == 20))
+
+ testing.db.execute(stmt)
+
def test_row_iteration(self):
users.insert().execute(
{'user_id': 7, 'user_name': 'jack'},