'Not all parameters were used in the SQL statement but I just want to update 1 column

I have a list of file names which I want to insert into my mySQL database. I have done the following:

cur.executemany("""INSERT INTO table (filename) VALUES(%s)""", folder_files)

However, I am getting:

mysql.connector.errors.ProgrammingError: Not all parameters were used in the SQL statement.

The table in the database does have 3 columns but I only want to insert data into the filename column.

My alternative (and working) code is

for each_pdf_file in folder_files:
    cur.execute("INSERT INTO table (filename) VALUES(%s)", (each_pdf_file,))
    print(each_pdf_file)

but this is incredibly slow (I have thousands of files to import into the database).

So how do I use the executemany? Or must I stick to my alternative code?



Solution 1:[1]

You dont have enough format strings to make the sql query.

format_string = ('%s, '* len(folder_files))[:-2]
cur.executemany("INSERT INTO table (filename) VALUES({})".format(format_string), folder_files)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MjZac