sparrow sparrow - 1 month ago 16
MySQL Question

pymysql returns error if long query is used

With the following code if I use a long query then I get an error. Is there a limit on the query size that I give?

Sorry, but I can't share the exact query that I'm passing. If the same query is given in MySQL workbench then the data is returned correctly. Any advice would be appreciated.

My code:

import pymysql.cursors
import pymysql
import pandas as pd


connection = pymysql.connect(host = host,
user = user,
db = db,
password = password,
port = port)

def sql_to_df(sql_query):
df = pd.read_sql(sql_query, connection)
connection.close()
return df

query = '''long query'''

#use pandas to pass SQL query
df = sql_to_df(query)
df.head()


This error is returned:

497 sql, index_col=index_col, params=params,
498 coerce_float=coerce_float, parse_dates=parse_dates,
--> 499 chunksize=chunksize)
500
501 try:

1602 if chunksize is not None:

TypeError: 'NoneType' object is not iterable

Answer

Using a different tool to query the database (mysql.connector). I was able to find additional insight into the error.

DatabaseError: Execution failed on sql 'SET SESSION group_concat_max_len = 1000000;

After removing that from my query it worked.

Comments