Connecting to Vertica database using SQLAlchemy

前端 未结 2 1074
野趣味
野趣味 2020-12-20 00:44

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\

相关标签:
2条回答
  • 2020-12-20 01:05

    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')
    
    0 讨论(0)
  • 2020-12-20 01:14

    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()')
    
    0 讨论(0)
提交回复
热议问题