ExaStatement#

class pyexasol.ExaStatement(connection, query=None, query_params=None, prepare=False, meta_nosql=False, **options)[source]#

Bases: object

This class executes and helps to fetch result set of single Exasol SQL statement.

Warning

Unlike typical Cursor object, ExaStatement is not reusable.

Note

pyexasol.ExaStatement may fetch result set rows as tuples (default) or as dict (set fetch_dict=True in connection options).

pyexasol.ExaStatement may 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.ExaStatement fetches 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:

tuple or dict depending on fetch_dict connection 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.

column_names()[source]#

List of column names.

columns()[source]#

Retrieves column information of returned data.

Returns:

A dict with keys as column names and values as dataType objects.

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 data must 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:

list of tuples or list of dict. Empty list if all rows were fetched previously.

Warning

This function may exhaust available memory.

fetchcol()[source]#

Fetches all values from the first column.

Returns:

list of values. Empty list if 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:

list of tuples or list of dict. Empty list if all rows were fetched previously.

fetchone()[source]#

Fetches one row of data.

Returns:

tuple or dict. None if all rows were fetched.

fetchval()[source]#

Fetches first column of first row.

Returns:

Value, None if all rows were fetched previously.

Tip

This may be useful for queries returning single value like SELECT count(*) FROM table.

rowcount()[source]#

Number of selected/processed rows.

Returns:

Total amount of selected rows for statements with result set (num_rows). Total amount of processed rows for DML queries (row_count).