copy_table¶
-
getml.database.
copy_table
(source_conn, target_conn, source_table, target_table=None)[source]¶ Copies a table from one database connection to another.
- Example:
A frequent use case for this function is to copy data from a data source into sqlite. This is a good idea, because sqlite is faster than most standard, ACID-compliant databases and also you want to avoid messing up a productive environment.
It is important to explicitly pass conn_id, otherwise the source connection will be closed when you create the target connection. What you pass as conn_id is entirely up to you, as long as the conn_id of the source and the target are different. It can be any name you see fit.
>>> source_conn = getml.database.connect_odbc( ... "MY-SERVER-NAME", conn_id="MY-SOURCE") >>> >>> target_conn = getml.database.connect_sqlite3( ... "MY-SQLITE.db", conn_id="MY-TARGET") >>> >>> data.database.copy_table( ... source_conn=source_conn, ... target_conn=target_conn, ... source_table="MY-TABLE" ... )
- Args:
- source_conn (
Connection
): The database connection to be copied from.
- target_conn (
Connection
): The database connection to be copied to.
- source_table (str):
The name of the table in the source connection.
- target_table (str, optional):
The name of the table in the target connection. If you do not explicitly pass a target_table, the name will be identical to the source_table.
- source_conn (