Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Can someone tell me what's wrong with this Syntax?

>>>y = 14
>>> cursor.execute("INSERT INTO accounts VALUES ('Bobby', %s)", (y))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 477, in execute
    stmt = operation % self._process_params(params)
  File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 355, in      
_process_params
    "Failed processing format-parameters; %s" % err)
    mysql.connector.errors.ProgrammingError: Failed processing format-parameters; argument   
    2 to map() must support iteration
share|improve this question

1 Answer 1

up vote 2 down vote accepted

y should be inside a tuple:

cursor.execute("INSERT INTO accounts VALUES ('Bobby', %s)", (y, ))

FYI, (y) is not a tuple - it is an int in parenthesis, adding comma (y,) makes it a tuple with one element inside:

>>> y = 14
>>> type((y))
<type 'int'>
>>> type((y,))
<type 'tuple'>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.