1

I have a very long list of values:

mylist = [1, 2, 3, 4, 5, 6 .......]

and the following query to insert them in to postgres database:

connection.execute(
        'INSERT INTO data_core_cftcreport VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,%s, %s)',
        mylist)

This works as expected however it doesn't look good....

My question: Is there any way I can shorten the VALUES declaration?

I tried to do this, kind of borrowing from MySql, but it didn't work:

connection.execute('INSERT INTO data_core_cftcreport VALUES %s', mylist)
kajetons
  • 4,481
  • 4
  • 26
  • 37
sretko
  • 611
  • 2
  • 7
  • 18
  • 2
    this might help you: https://stackoverflow.com/questions/8316176/insert-list-into-my-database-using-python – Alan Apr 13 '18 at 06:35

0 Answers0