0

I'm currently looping through the dataframe updating the SQL table for each primary key row, but this is taking a very long time.

Is there a quicker way to implement the following logic:

with engine.begin() as conn:
for i in range(0, len(df['primary_key'])):
        conn.execute('UPDATE SQL_TABLE
                            SET Column1 = df['Column1'].iloc[i]
                            WHERE primary_key = df['primary_key'].iloc[i]')
D.L
  • 4,339
  • 5
  • 22
  • 45
Matthew
  • 1
  • 1
  • I am not strong in SQL, but try moving out `conn.execute` from the Loop, - as it looks like you re-connecting during each loop and it takes time. Try writing it above `for i in range` loop – NoobVB Sep 01 '22 at 16:03
  • this one, looks like working and logical: https://stackoverflow.com/a/42468898/8805842 – NoobVB Sep 01 '22 at 16:11

0 Answers0