pyodbc: Unsupported type from Postgres `SQLGetData`

I’m trying to run a very simple query against an Amazon RedShift database:

SELECT TRIM(datname) FROM pg_database

I get the following error:

pyodbc.Error: ('07006', '[07006] Received an unsupported type from Postgres. (14) (SQLGetData)')

I’m using python 3.4.3 with pyodbc 3.1.1

My code is as follows:

>>> import pyodbc
>>> cnxn = pyodbc.connect('DSN=redshift-db')
>>> cursor = cnxn.cursor()
>>> cursor.execute("SELECT TRIM(datname) FROM pg_database")
<pyodbc.Cursor object at 0x7f0f57d95ab0>
>>> rows = cursor.fetchall()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.Error: ('07006', '[07006] Received an unsupported type from Postgres. (14) (SQLGetData)')

This code works when using other languages.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (8 by maintainers)

Most upvoted comments

Hello, just following up that my error was being caused by pointing the odbc.ini driver path at the psqlodbca.so file versus the psqlodbcw.so file. Sorry about that!

OK, I’m a bit baffled. I’ve setup a RedShift instance and connected with this driver: Amazon Redshift ODBC Driver 1.3.1.1000

I had trouble, but not the errors you are seeing. I switched the v4 branch and configured it using these lines:

cnxn = pyodbc.connect(DSN)
cnxn.setencoding(encoding='utf-8')
cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
cnxn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')

In all of my projects I use a global function that retrieve connections, giving me an easy place to set configuration, wrap with debugging connections if necessary, etrc.

What these do is configure everything to use UTF-8. Now, I’m on a Mac so it could need tweaking for other OSs. What are you using?