diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-12-21 13:39:56 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-12-21 13:39:56 -0500 |
| commit | d5bb919aa6d5b9961f85987dfaa58d5999910d15 (patch) | |
| tree | 3bf4c7b652e67b160584f3c28a654b572b02ce07 /test/sql/test_insert.py | |
| parent | afb3a528330fb9c0669d946cd065ff96bba8573d (diff) | |
| download | sqlalchemy-d5bb919aa6d5b9961f85987dfaa58d5999910d15.tar.gz | |
Call nextval() on sequence when doing INSERT from SELECT
Fixed bug where an INSERT from SELECT where the source table contains
an autoincrementing Sequence would fail to compile correctly.
Change-Id: I41eb9f65789a4007712ae61ed5fa23a9839a5128
Fixes: #3877
Diffstat (limited to 'test/sql/test_insert.py')
| -rw-r--r-- | test/sql/test_insert.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/test/sql/test_insert.py b/test/sql/test_insert.py index 2fa1860de..73731e952 100644 --- a/test/sql/test_insert.py +++ b/test/sql/test_insert.py @@ -1,7 +1,8 @@ #! coding:utf-8 from sqlalchemy import Column, Integer, MetaData, String, Table,\ - bindparam, exc, func, insert, select, column, text, table + bindparam, exc, func, insert, select, column, text, table,\ + Sequence from sqlalchemy.dialects import mysql, postgresql from sqlalchemy.engine import default from sqlalchemy.testing import AssertsCompiledSQL,\ @@ -238,6 +239,24 @@ class InsertTest(_InsertTestBase, fixtures.TablesTest, AssertsCompiledSQL): checkparams={"name_1": "foo"} ) + def test_insert_from_select_seq(self): + m = MetaData() + + t1 = Table( + 't', m, + Column('id', Integer, Sequence('id_seq'), primary_key=True), + Column('data', String) + ) + + stmt = t1.insert().from_select(('data', ), select([t1.c.data])) + + self.assert_compile( + stmt, + "INSERT INTO t (data, id) SELECT t.data, " + "nextval('id_seq') AS next_value_1 FROM t", + dialect=postgresql.dialect() + ) + def test_insert_from_select_cte_one(self): table1 = self.tables.mytable |
