Last active
May 22, 2016 04:56
-
-
Save ericsalim/1d12628826195b52c5d282c2326f5e00 to your computer and use it in GitHub Desktop.
Inserting 100k rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine | |
conn = None | |
try: | |
conn_str = "postgresql+psycopg2://postgres:password@localhost:5432/test" | |
engine = create_engine(conn_str, pool_size=3) | |
conn = engine.connect() | |
for i in range(0, 100000): | |
sql = "insert into table1 (a,b,c,d,e) values (%s,%s,%s,%s,%s)" | |
conn.execute(sql, (i, 'string for ' + str(i), 'string for ' + str(i), i*0.1, i*0.1)) | |
finally: | |
if conn is not None: conn.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment