Skip to content

Instantly share code, notes, and snippets.

@ericsalim
Last active May 22, 2016 04:56
Show Gist options
  • Save ericsalim/1d12628826195b52c5d282c2326f5e00 to your computer and use it in GitHub Desktop.
Save ericsalim/1d12628826195b52c5d282c2326f5e00 to your computer and use it in GitHub Desktop.
Inserting 100k rows
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