singlestoredb.connection.Cursor.execute

abstract Cursor.execute(query: str, args: Sequence[Any] | Dict[str, Any] | Any | None = None, infile_stream: RawIOBase | TextIOBase | Iterator[bytes | str] | Queue[bytes | str] | None = 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.

Parameters:
  • query (str) – The SQL statement to execute

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

  • infile_stream (io.RawIOBase or io.TextIOBase or Iterator[bytes|str], optional) – Data stream for LOCAL INFILE statement

Examples

>>> 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