Hi!
Maybe someone can help me.
Im trying to connect to a MySQL table to get some data and use it within MonetDB.
Eveything works fine, TILL... the query Im running on MySQL is bringing NO DATA.
As an example I put it as LIMIT 0 so I dont receive any row.
Eventhough I have considered that situation and have defined the array with null values, Im still getting an error.
Could not create a Numpy array from the return type.
Does anybody has an idea how to solve this issue?
Thks in advance!
Ariel
-----------------------------------------------------
DROP FUNCTION connect_to_mysql() ;
CREATE FUNCTION connect_to_mysql()
RETURNS TABLE(agr_id integer, agr_name string
) LANGUAGE PYTHON {
import datetime
import mysql.connector
cnx = mysql.connector.connect(user='XXXX', password='XXXX',host='192.168.15.5',database='XXXXX',use_pure=False)
cursor = cnx.cursor()
query = "SELECT agr_id, agr_name FROM AGR_Agreement LIMIT 0 "
cursor.execute(query)
allrows = cursor.fetchall()
ncols = len(cursor.description)
colnames = [cursor.description[i][0] for i in range(ncols)]
result = dict()
for col in range(ncols):
if len(allrows) == 0:
result[colnames[col]] = [None]
for row in range(len(allrows)):
if allrows[row][col] == None:
valor = None
else:
valor = str(allrows[row][col])
try:
result[colnames[col]].append(valor)
except KeyError:
result[colnames[col]] = [valor]
cursor.close()
cnx.close()
return result
};
sql>SELECT * FROM connect_to_mysql() ;
Could not create a Numpy array from the return type.