In a python script, I need to run a query on one data source and insert each row from this query into a table on another data source. I usually do this with a single insert / select statement with a connection to the connected tsql server, but I don't have a connected connection to the server with this particular data source.
I am having trouble finding a simple pyobbc example. Here is how I would do it, but I assume that executing the insert statement inside the loop is pretty slow.
result = ds1Cursor.execute(selectSql) for row in result: insertSql = "insert into TableName (Col1, Col2, Col3) values (?, ?, ?)" ds2Cursor.execute(insertSql, row[0], row[1], row[2]) ds2Cursor.commit()
Is there a better way to insert records with pyodbc? Or is it a relatively effective way to do it anyway. I am using SqlServer 2012 and the latest versions of pyopbc and python.
source share