jeudi 24 septembre 2015

Block insert from array to SQLITE in python

So I read this article that says inserting in blocks beats one row at a time:
Which is faster: multiple single INSERTs or one multiple-row INSERT?

And I read this article that suggests how to take rows of text and insert them into a mysql store:
How to use python mysqldb to insert many values at once

My procedure goes like this:

  • get vat of strings from input source
  • pop out the few (10's) of chunks of interest
  • populate an array with them, one chunk to one cell in a row
  • repeat until the array is full
  • try put the rows into the store with the input command

my problem is that when I try to use the following code for an array with ~100+ rows

cur.execute("INSERT INTO OpStatus VALUES('%s',%s,...,%s)" % my_array)

I currently have one "%s" for each column in the table.

It gives me the following error.

TypeError: not enough arguments for format string

My question is:
How do I reform my array or input statement so that I can make this a batch (not row) insert into the SQLITE table?

DISCLAIMER: It has been a few years since I used python. If you need to point me in a direction, or ask clarifying questions, please feel free.

Aucun commentaire:

Enregistrer un commentaire