Loading...

verticapy.connection.set_connection#

verticapy.connection.set_connection(conn: Connection) None#

Saves a custom connection to the VerticaPy object. This allows you to specify, for example, a JDBC or ODBC connection. This should not be confused with a native VerticaPy connection created by the new_connection() function.

Examples#

Create a connection using the official Vertica Python client:

Note

You can use any connector (ODBC, JDBC, etc.) as long it has both fetchone and fetchall methods. However, note that VerticaPy works most efficiently with the native client because of its support for various complex data types and certain Vertica optimizations.

import vertica_python

conn_info = {
    'host': "10.211.55.14",
    'port': 5433,
    'user': "dbadmin",
    'password': "XxX",
    'database': "testdb",
}
conn = vertica_python.connect(** conn_info)

Set up the connector:

Warning

As this connector is used throughout the entire API, if it’s closed, you’ll need to create a new one. This is why, in some cases, it’s better to use auto-connection, which automatically create a new connection if the current one is closed.

from verticapy.connection import set_connection

set_connection(conn)

See also

new_connection() : Creates a new VerticaPy connection.