ExaStatement#
- class pyexasol.ExaStatement(connection, query=None, query_params=None, prepare=False, meta_nosql=False, **options)[source]#
Bases:
objectThis class executes and helps to fetch result set of single Exasol SQL statement.
Warning
Unlike typical Cursor object, ExaStatement is not reusable.
Note
pyexasol.ExaStatementmay fetch result set rows astuples(default) or asdict(set fetch_dict=True in connection options).pyexasol.ExaStatementmay use custom data-type mapper during fetching (set fetch_mapper=<func> in connection options). Mapper function accepts two arguments (raw value and dataType object) and returns custom object or value.pyexasol.ExaStatementfetches big result sets in chunks. The size of chunk may be adjusted (set fetch_size_bytes=<int> in connection options).- Public Attributes:
execution_time:Execution time of SQL statement. It is measured by wall-clock time of WebSocket request, so real execution time is a bit faster.
- __init__(connection, query=None, query_params=None, prepare=False, meta_nosql=False, **options)[source]#
- Parameters:
connection
query
query_params
prepare
meta_nosql
options – additonal kwargs
- __iter__()[source]#
The best way to fetch result set of statement is to use iterator:
- Yields:
tupleordictdepending onfetch_dictconnection option.
Examples
>>> st = pyexasol.execute('SELECT * FROM table') ... for row in st: ... print(row)
- close()[source]#
Closes result set handle if it was opened.
Warning
You won’t be able to fetch next chunk of large dataset after calling this function, but no other side effects.
- columns()[source]#
Retrieves column information of returned data.
- Returns:
A
dictwith keys ascolumn namesand values asdataTypeobjects.
Notes
The dict will containt the following data:
Names
Type
Description
type
string
column data type
precision
number
(optional) column precision
scale
number
(optional) column scale
size
number
(optional) maximum size in bytes of a column value
characterSet
string
(optional) character encoding of a text column
withLocalTimeZone
true, false
(optional) specifies if a timestamp has a local time zone
fraction
number
(optional) fractional part of number
srid
number
(optional) spatial reference system identifier
- execute_prepared(data=None)[source]#
Execute the prepared statement with tuples of parameters (single or bulk execution).
- Parameters:
data – Tuples of values for the parameters of the prepared statement.
Note
Every tuple in
datamust match the quantity and datatype of placeholders in the prepared SQL statement.Examples:
>>> con = ExaConnection(...) >>> exa_stmt = con.create_prepared_statement( ... sql="INSERT INTO S.T VALUES (?, ?)", ...) >>> exa_stmt.execute_prepared( [('A', 1), ('B', 2), ('C', 3)] )
- fetchall()[source]#
Fetches all remaining rows.
- Returns:
listoftuplesorlistofdict. Emptylistif all rows were fetched previously.
Warning
This function may exhaust available memory.
- fetchcol()[source]#
Fetches all values from the first column.
- Returns:
listof values. Emptylistif all rows were fetched previously.
- fetchmany(size=10000)[source]#
Fetch multiple rows.
- Parameters:
size – Set the specific number of rows to fetch (Default:
10000)- Returns:
listoftuplesorlistofdict. Empty list if all rows were fetched previously.