Passing a single argument to cursor.execute()
, or the “missing comma”
- comma
- tuple
- sql
The asker is trying to execute SQL with a single placeholder and is passing the argument instead of a 1-tuple of arguments to execute. For example with the mysql.connector
:
stmt = "SELECT * FROM users WHERE username = %s"
username = ('email@example.com')
result = cursor.execute(stmt, username)
One way to fix is to add the missing comma in order to turn username
into a tuple:
username = ('email@example.com',)
or
cursor.execute(stmt, (username,))
Any sequence should do, so a list would work as well:
cursor.execute(stmt, [username])
The relevant DB-API v2.0 link.
- How to create a tuple with only one element
- psycopg2 how deal with TypeError: not all arguments converted during string formatting
- Python MySQL Connector database query with %s fails
- TypeError: 'int' object does not support indexing
- sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 74 supplied
- Number of MySQL query parameters match arguments passed to execute, but Python raises "not all arguments converted"