verticapy.connection.current_connection#
- verticapy.connection.current_connection() GlobalConnection #
Returns the current database connection. If the connection is closed, VerticaPy attempts to reconnect with the existing connection.
If the connection attempt fails, VerticaPy attempts to reconnect using stored credentials. If this also fails, VerticaPy attempts to connect using an auto connection. Otherwise, VerticaPy attempts to connect to a VerticaLab Environment.
Examples#
Get the current VerticaPy connection:
from verticapy.connection import current_connection conn = current_connection() conn
<vertica_python.vertica.connection.Connection at 0x118c1f8d0>
After the connection is established, you can execute SQL queries directly:
Note
Please refer to your connector’s API reference for a comprehensive list of its functionalities.
conn.cursor().execute("SELECT version();").fetchone()
['Vertica Analytic Database v12.0.4-0']
See also
current_cursor()
: Returns the current VerticaPy cursor.new_connection()
: Creates a new VerticaPy connection.set_connection()
: Sets the VerticaPy connection.