Cursor.executemany(query: str, args: Sequence[Sequence[Any] | Dict[str, Any] | Any] | None = None) int

Execute SQL code against multiple sets of parameters.

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

  • query (str) – The SQL statement to execute

  • args (iterable of iterables or dicts, optional) – Sets of parameters to substitute into the SQL code


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

Number of rows affected