Skip to content

python sql insert statement inserting values with quotes in database

I am trying to insert data into Mysql in python using the below statements

cursor.execute('INSERT INTO batch_details (batch_id,plant_id,product_code) VALUES ("%s","%s","%s")', (id, plantcode, pcode))

Here id =”75″, plantcode=”2″, pcode=”FG”

But my values in database are inserted with single quote in mysql database i.e ’75’,’2′,’FG’

I do not why the values are inserted with single quotes. The syntax of sql query seems to be right.



%s means the value you’re providing is to be interpreted as a string. For the ones you want to be integers, try using %d instead. You might also need to get rid of the quote characters around the %d parts in your VALUES list if you want SQL to interpret the value as a number and not a string.

Also, when different programs or libraries print a string, some will print it with single-quote characters, some will print it with double-quote characters. Either way it’s still a string in your database, it’s just printed to the screen in a stylistically different way.

2 People found this is helpful