Skip to content

Commit bb9ec0c

Browse files
committed
Added multivalue_insert support
1 parent a0e997a commit bb9ec0c

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

base.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ class SnowflakeDialect(default.DefaultDialect):
423423

424424
# The dialect supports a native ENUM construct.
425425
supports_native_enum = False
426-
427-
# The dialect supports inserting multiple rows at once
426+
427+
# The dialect supports inserting multiple rows at once.
428428
supports_multivalues_insert = True
429429

430430
preparer = SnowflakeIdentifierPreparer
@@ -433,10 +433,8 @@ class SnowflakeDialect(default.DefaultDialect):
433433
statement_compiler = SnowflakeCompiler
434434
execution_ctx_cls = SnowflakeExecutionContext
435435

436-
# indicates symbol names are
437-
# UPPERCASEd if they are case insensitive
438-
# within the database.
439-
# if this is True, the methods normalize_name()
436+
# indicates symbol names are UPPERCASEd if they are case insensitive
437+
# within the database. If this is True, the methods normalize_name()
440438
# and denormalize_name() must be provided.
441439
requires_name_normalize = True
442440

test/test_core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ def test_insert_tables(engine_testaccount):
160160
Inserts data into tables
161161
"""
162162
metadata = MetaData()
163-
users, addresses = _create_users_addresses_tables(engine_testaccount,
164-
metadata)
163+
users, addresses = _create_users_addresses_tables(
164+
engine_testaccount, metadata)
165165

166+
conn = engine_testaccount.connect()
166167
try:
167168
# inserts data with an implicitly generated id
168169
ins = users.insert().values(name='jack', fullname='Jack Jones')
@@ -171,7 +172,6 @@ def test_insert_tables(engine_testaccount):
171172
results.close()
172173

173174
# inserts data with the given id
174-
conn = engine_testaccount.connect()
175175
ins = users.insert()
176176
conn.execute(ins, id=2, name='wendy', fullname='Wendy Williams')
177177

@@ -312,6 +312,7 @@ def test_insert_tables(engine_testaccount):
312312
results = engine_testaccount.execute(s).fetchall()
313313
assert results[-1] == ('Wendy Williams',)
314314
finally:
315+
conn.close()
315316
# drop tables
316317
addresses.drop(engine_testaccount)
317318
users.drop(engine_testaccount)

test/test_multivalues_insert.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2012-2018 Snowflake Computing Inc. All right reserved.
5+
#
6+
7+
from sqlalchemy import (Integer, String, Sequence)
8+
from sqlalchemy.schema import (Table, Column, MetaData)
9+
from sqlalchemy.sql import select
10+
11+
12+
def test_insert_table(engine_testaccount):
13+
metadata = MetaData()
14+
users = Table('users', metadata,
15+
Column('id', Integer, Sequence('user_id_seq'),
16+
primary_key=True),
17+
Column('name', String),
18+
Column('fullname', String),
19+
)
20+
metadata.create_all(engine_testaccount)
21+
22+
data = [{
23+
'id': 1,
24+
'name': 'testname1',
25+
'fullname': 'fulltestname1',
26+
}, {
27+
'id': 2,
28+
'name': 'testname2',
29+
'fullname': 'fulltestname2',
30+
}]
31+
conn = engine_testaccount.connect()
32+
try:
33+
# using multivalue insert
34+
conn.execute(users.insert(data))
35+
results = conn.execute(select([users]).order_by('id'))
36+
row = results.fetchone()
37+
assert row['name'] == 'testname1'
38+
39+
finally:
40+
conn.close()
41+
users.drop(engine_testaccount)

0 commit comments

Comments
 (0)