I'm trying to query a table from an Informix database using pyodbc and write the results to a CSV file with the below code:
import pyodbc
import pandas as pd
server = '***.***.***.***'
dsn= 'informixdb'
username = 'user'
password = 'user123'
csvFile = r"C:\temp\bookings.csv"
conn = pyodbc.connect(dsn=f'{dsn}', uid=f'{username}', pwd=f'{password}')
cursor = conn.cursor()
sql = "SELECT FIRST 5 * from bookingsd"
df = pd.read_sql_query(sql, conn)
df.to_csv(csvFile, index=False)
I've also tried the following:
import pyodbc, csv
server = '***.***.***.***'
dsn= 'informixdb'
username = 'user'
password = 'user123'
csvFile = r"C:\temp\bookings.csv"
conn = pyodbc.connect(dsn=f'{dsn}', uid=f'{username}', pwd=f'{password}')
cursor = conn.cursor()
sql = "SELECT FIRST 5 * from bookingsd"
rows = cursor.execute(sql)
with open(csvFile, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow([x[0] for x in cursor.description]) # column headers
for row in rows:
writer.writerow(row)
Both produce the same error:
ODBC SQL type -103 is not yet supported. column-index=136 type=-103', 'HY106'
It appears the error is occurring for the pyodbc cursor object (i.e. rows). Does anyone know what this error is referring to?