abstract Cursor.execute(query: str, args: Optional[Union[Sequence[Any], Dict[str, Any], Any]] = None) int

Execute a SQL statement.

Queries can use the format-style parameters (%s) when using a list of paramters or pyformat-style parameters (%(key)s) when using a dictionary of parameters.

  • query (str) – The SQL statement to execute

  • args (Sequence or dict, optional) – Parameters to substitute into the SQL code


>>> cur.execute('select * from mytable')
>>> cur.execute('select * from mytable where id < %s', [100])
>>> cur.execute('select * from mytable where id < %(max)s', dict(max=100))
Return type

Number of rows affected