Skip to content Skip to sidebar Skip to footer

Connecting To Vertica Database Using Sqlalchemy

I'm trying to connect to a Vertica database using SQLAlchemy. I came across and installed a Vertica dialect at https://github.com/jamescasbon/vertica-sqlalchemy. I've also installe

Solution 1:

SQLAlchemy is using unixODBC to connect to Vertica. You need to install the drivers and set up a DSN

You should be able to connect with these parameters. This is what worked for me in my previous SQLAlchemy / Vertica project. Also, if this doesn't work, I would make sure it is configured properly and that you can connect using isql (comes with unixODBC).

drivername='vertica+pyodbc',
username='myuser',
password='mypassword',
host='hostname',
database='DBNAME',

You can also do this for a DSN connection:

engine = create_engine('vertica+pyodbc://username:password@mydsn')

Solution 2:

This is setup for Ubuntu 14.04 assuming you have a driver installed in /opt/vertica/ and using HP Vertica from this Dockerfile https://hub.docker.com/r/sumitchawla/vertica/ and have https://github.com/jamescasbon/vertica-sqlalchemy.

/etc/vertica.ini

[Driver]ErrorMessagesPath = /opt/vertica/lib64/
ODBCInstLib = /usr/lib/x86_64-linux-gnu/libodbcinst.so
DriverManagerEncoding=UTF-16

~/.odbc.ini

[ODBC Data Sources]
vertica = "My Database"

[verticadsn]
Description = My Database
Driver = /opt/vertica/lib64/libverticaodbc.so
Database = docker
Servername = 127.0.0.1
UID = dbadmin
PWD =

If you did everything right, this command should return your version of Vertica

engine = create_engine('vertica+pyodbc://dbadmin:@verticadsn')
engine.connect().scalar('selectversion()')

Post a Comment for "Connecting To Vertica Database Using Sqlalchemy"