Connecting to Vertica database using SQLAlchemy

本小妞迷上赌 提交于 2019-12-01 12:28:55

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')

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('select version()')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!