Execute sql insert statements via sql alchemy within for loop

I need to extract a bunch of records within a singlestore database and insert the records into another table. For performance, the ideal way to do this is to create a query string with an Insert Into statement and iterate through on a daily basis.

I can’t seem to get python to execute the query in the database, but it appears to run successfully?

fh = 'file_containing_insert_select_query.sql'
qry = open(fh).read()
for i in range(2):
    qry_new = some_custom_function_to_replace_dates(qry, i)
    engine = tls.custom_engine_function()
    engine.execute(qry_new)

I’ve verified that the sql statements created by my custom function can be copy/pasted to a sql editor and executed successfully, but it won’t run in python… any thoughts?

It’s not clear what the issue is; would need to see the error message to have more to go on. But if you want it to run really fast, it’s usually better to use set-oriented SQL, like INSERT INTO targetTbl … SELECT FROM …;

That way, it doesn’t have to round-trip through the client app.