Skip to content

cursor.fetchall() returns a tuple on empty result #1042

@nmenardg-keeper

Description

@nmenardg-keeper

Describe the bug
Doing a SELECT, if the result set is empty (no row found), cursor.fetchall() returns () (empty tuple)

To Reproduce

import pymysql
con = pymysql.connect(...)
with con.cursor() as cursor:
    cursor.execute("select * from information_schema.TABLES where TABLE_NAME = 'patate';")
    data = cursor.fetchall()

Expected behavior
PEP-0249 mentions:

returning them as a sequence of sequences (e.g. a list of tuples)
https://peps.python.org/pep-0249/#fetchall

I would expect an empty list []

Environment

  • OS: Manjaro Linux
  • Server and version: MySQL 8.0.20
  • PyMySQL version: 1.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions