Getting ?? as output of unicode characters while connection Netezza with Python

Viewed 171

I am trying to access unicode (Chinese, Japanese, etc) characters in python code from a Netezza database. For the connection, I am using the Netezza odbc driver and sqlalechmy, and a table in netezza which has an nvarchar type column which has chinese characters in it. While accessing that chinese character using python code, the output was ?? instead of actual data.

Table having two columns, one is with datatype id and other is with datatype nvarchar:

id(int)  Data(nvarchar)
1        你好
2        你好
3        你好

Conection code:

connecting_string="DRIVER={NetezzaSQL};SERVER=hostname;PORT=5480;DATABASE=databaseName;UID=userNamw;PWD=password"
sqlparams = parse.quote_plus(connecting_string)
engine = create_engine(f"netezza+pyodbc:///?odbc_connect={sqlparams}")

netezzaConnection = engine.connect()
1 Answers

This was a known limitation when nzalchemy was developed with pyodbc. This is working fine with nzpy dialect of nzalchemy.

>>> import sqlalchemy
>>> import nzalchemy
>>> engine = sqlalchemy.create_engine("netezza+nzpy://admin:password@localhost:5480/DB1")
>>> conn = engine.connect()
>>> res = conn.execute("select * from t7")
>>> print(res.fetchall())
[('你好',)]

Will work on pyodbc.

Related