Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Q] An error occurs when the record count of read_sql is 0 #43

Closed
takisawa opened this issue Jun 27, 2018 · 5 comments
Closed

[Q] An error occurs when the record count of read_sql is 0 #43

takisawa opened this issue Jun 27, 2018 · 5 comments

Comments

@takisawa
Copy link

I executed the following Python script.

pandas.read_sql("SELECT * FROM td_table WHERE 1=0", td)
=> tdclient.errors.InternalError: row index out of bound (0 out of 0)

Is this in the specifications?

In the case of mysql-connector-python, the result is as follows.

pandas.read_sql("SELECT * FROM mysql_table WHERE 1=0", mysql)
=> Empty DataFrame
@takisawa takisawa changed the title [Q] An error occurs when the number of select statement is 0 [Q] An error occurs when the number of read_sql is 0 Jun 27, 2018
@takisawa takisawa changed the title [Q] An error occurs when the number of read_sql is 0 [Q] An error occurs when the record count of read_sql is 0 Jun 27, 2018
@yyuu
Copy link
Member

yyuu commented Jun 28, 2018

.fetchall()
Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor's arraysize attribute can affect the performance of this operation.

An Error (or subclass) exception is raised if the previous call to .execute*() did not produce any result set or no call was issued yet.

Hmm, according to pep-0249, it looks like raising exception on "did not produce any result set" is in specification. However, as a user, I feel that raising exception on empty result set is troublesome than beneficial.... I guess that the point is that the interpretation of "any result set"; if empty result is some result set or not 🤔

@yyuu
Copy link
Member

yyuu commented Jun 28, 2018

I briefly checked other DBAPI 2 implementations, and confirmed that returning empty list is common behavior at least.

fetchall()
Fetches all (remaining) rows of a query result, returning a list. Note that the cursor’s arraysize attribute can affect the performance of this operation. An empty list is returned when no rows are available.
https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.fetchall

fetchall()
Fetch all (remaining) rows of a query result, returning them as a list of tuples. An empty list is returned if there is no more record to fetch.
http://initd.org/psycopg/docs/cursor.html?highlight=fetchall#cursor.fetchall

I'll try modifying the code to change the behavior later. Thanks letting us know anyways!

@takisawa
Copy link
Author

I briefly checked other DBAPI 2 implementations, and confirmed that returning empty list is common behavior at least.

I'll try modifying the code to change the behavior later. Thanks letting us know anyways!

Thank you very much!!!
I am looking forward to it!

@yyuu
Copy link
Member

yyuu commented Jun 29, 2018

I've released 0.12.1.dev0 to PyPI with including the fix. Please give it a try if it is working as you expected.

https://pypi.org/project/td-client/0.12.1.dev0/

@takisawa
Copy link
Author

@yyuu

Thank you for your quick and great work!!!
I will try using 0.12.1.dev0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants