1

I am trying to insert with python (v 2.7.6) a variable with multiple entries into MySQL (Ver 14.14 Distrib 5.5.43) table. The code is as follows :

cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS Stations(     \
            StationsID  INT AUTO_INCREMENT,           \
            Code      VARCHAR(3)       ,              \
            PRIMARY KEY pk_Stations (StationsID)      \
            );");

cur.executemany("INSERT INTO Stations (Code) VALUES(?)", sns);

sns variable has the following form:

array(['PAL', 'TT1', 'BAL', 'MHD', 'BI5', 'CB4'],dtype='|S3')

I am getting the following error:

File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 199, in executemany
    if not args: return
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Could you please give me a help here?

Cleb
  • 25,102
  • 20
  • 116
  • 151
pakoun
  • 65
  • 8

1 Answers1

1

Problem solved. The variable should be a list and it was a numpy array.

pakoun
  • 65
  • 8