Iterable#
This example exports a table to a list with export_to_list and imports it back with
import_from_iterable. Export always returns a list, but import accepts any iterable.
IMPORT / EXPORT to and from a list or other iterable#
"""
HTTP transport
EXPORT and IMPORT from Exasol to and from lists
"""
import examples._config as config
import pyexasol
def connect() -> pyexasol.ExaConnection:
# Connect with compression enabled
return pyexasol.connect(
dsn=config.dsn,
user=config.user,
password=config.password,
schema=config.schema,
compression=True,
websocket_sslopt=config.websocket_sslopt,
)
# Prepare empty table
with connect() as C:
C.execute("TRUNCATE TABLE users_copy")
# Export to list
with connect() as C:
users = C.export_to_list("users")
statement = C.last_statement()
print(users[0])
print(users[1])
print(f"EXPORTED {statement.rowcount()} rows in {statement.execution_time}s")
# Import from list (or any other iterable)
with connect() as C:
C.import_from_iterable(users, "users_copy")
statement = C.last_statement()
print(f"IMPORTED {statement.rowcount()} rows in {statement.execution_time}s")