Insert rows slow?

Anvil bulk inserts are slow.
Wrapping the function in a transaction helps speeding it up a little, but there still are thousands of python objects being created and executing thousands of sql statements.

Depending on your requirements, you can:

  • Split the insert in chunks of 1000 rows. It will still take longer than 30 seconds but it will work. But you will not be able to wrap the whole operation in one transaction, you will have one transaction per 1000 row chunk
  • Use sql and build the sql string, bypassing the slow orm. This will be the fastest option, but you need a dedicated plan
  • Use an uplink script. Will be still slow, but it will work in one single transaction, if that’s what you need.
1 Like