Skip to content
Advertisement

How can I Insert multiple rows with one query

I made a code allowing me to GET data from an API and insert it into a database. But I encounter a problem my api contains about 20 million data and to insert everything in my database it will take me 43 days :)

I think the problem comes from the fact that I insert the data one by one.

That’s why I’m looking for how to execute all my queries at once.

The problem is that I get my data as a list[dict] like that :

JavaScript

Currently my code looks like this :

JavaScript

would you have any idea how to do it?

Advertisement

Answer

You can do with ‘executemany’.

example

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement