You are using the correct approach by doing bulk update with single query.
The reason why it takes that long is because the table doesn't have index on the sometable.column1
. It has only primary index on column id
.
Your update query uses sometable.column1
in where clause to identify record. So database has to scan through the all table records for every single column update.
To make update run much faster you need to update your table schema definition code to add index creation to the column1 definition with , index=True
:
sometable = Table('sometable', metadata,
Column('id', Integer, Sequence('sometable_id_seq'), primary_key=True),
Column('column1', Integer, index=True),
Column('column2', Integer),
)
I tested updated code in my machine - it took <2 seconds for the program to run.
BTW kudos to your question description - you put all code needed to reproduce your problem.