SQLAlchemy Vertica Dialect

0.0.5 · maintenance · verified Fri Apr 17

SQLAlchemy-Vertica provides a dialect for connecting SQLAlchemy to Vertica databases, leveraging the `vertica-python` driver. It allows users to interact with Vertica using SQLAlchemy's ORM and SQL Expression Language. The current version is 0.0.5, and the project appears to be in maintenance mode with infrequent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to a Vertica database using `sqlalchemy-vertica` and execute a simple SQL query. Ensure `VERTICA_USER`, `VERTICA_PASSWORD`, `VERTICA_HOST`, `VERTICA_PORT`, and `VERTICA_DATABASE` are correctly configured, preferably via environment variables for production systems.

import os
from sqlalchemy import create_engine, text

# Replace with your actual Vertica connection details
# It's recommended to use environment variables for sensitive info.
VERTICA_USER = os.environ.get("VERTICA_USER", "dbadmin")
VERTICA_PASSWORD = os.environ.get("VERTICA_PASSWORD", "password")
VERTICA_HOST = os.environ.get("VERTICA_HOST", "localhost")
VERTICA_PORT = os.environ.get("VERTICA_PORT", "5432")
VERTICA_DATABASE = os.environ.get("VERTICA_DATABASE", "VMART")

connection_string = (
    f"vertica+vertica_python://{VERTICA_USER}:{VERTICA_PASSWORD}"
    f"@{VERTICA_HOST}:{VERTICA_PORT}/{VERTICA_DATABASE}"
)

try:
    engine = create_engine(connection_string)
    with engine.connect() as connection:
        # Example: Execute a simple query
        result = connection.execute(text("SELECT 1 as test_col"))
        print(f"Connection successful! Result: {result.scalar()}")
except Exception as e:
    print(f"Failed to connect or execute query: {e}")

view raw JSON →