0

Here is my code to read from some data into MySql, the Mysql table contains 3 columns that in one of the columns I want to insert items of an array, each into a new row, and I do not want to have duplicate rows:

db = MySQLdb.connect("127.0.0.1", "root", "M0", "my", local_infile=True,use_unicode=True, charset="utf8")
cursor = db.cursor()
r=["2","3"]
params = ['?' for item in r]
sql="insert ignore into array (firt,last_name,arrays) values 'nina','sa',(%s);" % ','.join(params)
cursor.execute(sql,r)
db.commit();
db.close()

I have already looked into this post [1] as well !

However, on both of them I get this error:

_mysql_exceptions.ProgrammingError: not all arguments converted during string formatting

any suggestions, please?

nina_dev
  • 625
  • 2
  • 10
  • 19

1 Answers1

0

Why can't you just iterate over the set

r=set(["2","3"])
for item in r:
    sql="insert ignore into array (firt,last_name,arrays) values 'nina','sa',({})".format(item)
    cursor.execute(sql)
mad_
  • 8,121
  • 2
  • 25
  • 40
  • A follow up question has been posted: https://stackoverflow.com/questions/51824426/having-multiple-lists-and-inserting-their-values-into-mysql – nina_dev Aug 13 '18 at 14:15