0

I am trying to generate a list of SQL statements to execute, but the current code I believe commits them one by one:

    for batch in batches: # batch is a list of dictionary objects, batches is a list of lists
                
        for obj in batch: # for dictionary object in list
            
            with engine.connect() as connection:
                overwrite_failure = context['retry_failure'] == True and obj['status'] in ['success', 'critical failure']
    
                if overwrite_failure:
                    # load_deletes returns a string query which is escaped and formatted by .execute()
                    query_one, query_two = load_deletes(obj, table_name, columns, unique_cols, should_overwrite, identifier)
                    
                    connection.execute(query_one, obj)
                    connection.execute(query_two, obj)
                    
                else:
                  # load_updates returns a string query which is escaped and formatted by .execute()
                    query = load_updates(obj, table_name, columns, unique_cols, should_overwrite)
                    connection.execute(query, obj)

1 Answer 1

1

Init the DB connection outside the loops. Also make sure the auto_commit setting is off.

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.