0

I have this code:

SQL = 'INSERT INTO teste(id,completed) VALUES(%(id)s, %(completed)s);'

data = {
  'id':1,
  'completed':False}

cursor.execute(SQL, data)
connection.commit()
connection.close()
cursor.close()

and this is working just fine!

Question: How do I add records in bulk? I tried to change data to this:

data = {
      'id':[1,2,3],
      'completed':[False,False,True]}

but if fails.

snakecharmerb
  • 36,887
  • 10
  • 71
  • 115
merchmallow
  • 692
  • 2
  • 11
  • 2
    Does this answer your question? [psycopg2: insert multiple rows with one query](https://stackoverflow.com/questions/8134602/psycopg2-insert-multiple-rows-with-one-query) – snakecharmerb Jan 15 '22 at 13:46

0 Answers0