3
import sqlalchemy as sa
conn = "vertica+pyodbc://dbadmin:password@VMart"
sa.create_engine(conn, pool_size=10, max_overflow=20)
%load_ext sql
%sql vertica+pyodbc://VMart

error

(pyodbc.InterfaceError) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

(Background on this error at: http://sqlalche.me/e/rvf5)
Connection info needed in SQLAlchemy format, example:

 postgresql://username:password@hostname/dbname<br>
           or an existing connection: dict_keys([])

First

import sqlalchemy as sa
import urllib
sa.create_engine('vertica+vertica_python://dbadmin:password@192.168.11.132:5433/VMart')
%load_ext sql
%sql vertica+pyodbc://VMart

Second

import sqlalchemy as sa
sa.create_engine('vertica+vertica_python://dbadmin:password@VMart')

import pyodbc

Third

conn = pyodbc.connect("DRIVER=Vertica;SERVER=192.168.11.132;DATABASE=VMart;PORT=5433;UID=dbadmin;PWD=password")

same error

error but I already test vertica odbc in windows10. It connect successfuled

(pyodbc.InterfaceError) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') (Background on this error at: http://sqlalche.me/e/rvf5)
Connection info needed in SQLAlchemy format, example:

postgresql://username:password@hostname/dbname
or an existing connection: dict_keys([])

Ramprasath Selvam
  • 3,868
  • 3
  • 25
  • 41

1 Answers1

0

Might not get to the root of your problem, but below are a few steps that could help in making a connection:

  1. Have you tried installing sqlalchemy-vertica driver?. Specifically I would recommend installing with vertica-python. This is one driver for the connection with vertica in python and I found it works pretty well (caveats later)
pip install sqlalchemy-vertica[vertica-python]
  1. Have you imported vertica-python? Not sure this will impact the code, but it definitely helps to remove as an issue. In case you have not installed it:
pip install vertica-python

Edit: As a matter of fact if all you need is to read data, this package worked well for me on itself. Below is a sample code that is currently working for me:

import vertica_python
conn_info = {
    'host': 'host-ip',
    'port': port,
    'user': 'usr',
    'password':password,
    'database': 'db',
    # autogenerated session label by default,
    'session_label': 'current_session',
    # default throw error on invalid UTF-8 results
    'unicode_error': 'strict',
    # SSL is disabled by default
    'ssl': False,
    # using server-side prepared statements is disabled by default
    'use_prepared_statements': False,
    # connection timeout is not enabled by default
    # 'connection_timeout': 1
}

vertica_python.connect(**conn_info)
  1. Making the connection. I would recommend your first line to connect:
sa.create_engine('vertica+vertica_python://dbadmin:password@192.168.11.132:5433/VMart')

Caveats using Pandas:

  1. I had issues with sending str variables to the db using pandas.to_sql. If that is your case, just make sure to pass the types explicitly for those columns as VARCHAR (it will force to TEXT for some reason). This function from this question might help you:
def updateType(df_para):
    dtypedict = {}  # create and empty dictionary
    for i,j in zip(df_para.columns, df_para.dtypes):
        if "object" in str(j):
            dtypedict.update({i: sa.types.VARCHAR})

    return dtypedict

updatedict = updateType(df)
  1. I would receive a weird error when using to_sql:

NotImplementedError: executemany is implemented for simple INSERT statements only.

Did not find a proper solution but tried to remediate it using the chunksize param, and it seems to have worked.

realr
  • 3,652
  • 6
  • 23
  • 34
  • Thank for your help. I have already tried it before and I just reinstall anaconda-navigator. Would I miss any libraries? 1. conda update sqlalchemy 2. pip install sqlalchemy-vertica[pyodbc,vertica-python] 3. pip install pyodbc 4.pip install ipython-sql 5. pip install psycopg2 6. pip install six However, it stills the same error again. I try to find it out and I don't get closed. Anything may suggest me – Chiramet Charoennakasit Aug 08 '19 at 03:00
  • Thank for your help. I have already tried it before and I just reinstall anaconda-navigator. Would I miss any libraries? 1. conda update sqlalchemy 2. pip install sqlalchemy-vertica[pyodbc,vertica-python] 3. pip install pyodbc 4.pip install ipython-sql 5. pip install psycopg2 6. pip install six import sqlalchemy as sa import urllib sa.create_engine('vertica+vertica_python://dbadmin:password@192.168.11.132:5433/VMart') %load_ext sql %sql vertica+pyodbc://VMart However, it stills the same error again. I try to find it out and I don't get closed. Anything may suggest me – Chiramet Charoennakasit Aug 08 '19 at 03:07
  • Hi @ChirametCharoennakasit I dont see in your list `vertica_python` itself [here](https://github.com/vertica/vertica-python). It is a good package and connected to the example provided above. I just managed to connect yesterday and it worked well. As a matter of fact, if all you need is to read data, you should only need this package. I edited the answer to add a code snippet that is working for me to read data. – realr Aug 08 '19 at 03:21
  • It is working now but I have to use it another way. I would like to use sqlalchemy – Chiramet Charoennakasit Aug 10 '19 at 14:52