fetchall() Method

Fetches all of the remaining rows of a query result as an array of sequences.

Syntax

cursor.fetchall()

Returns

Returns an array of all remaining rows in the query result.

Remarks

The uselob parameter cannot be used with fetchall, use the fetchone method to fetch LOB data as LOB class objects.

An error is returned if the previous call to an execute method did not produce a result set or if a call has not been issued yet.

Example

Use the following example to create a table:

cursor = conn.cursor()
cursor.execute("CREATE TABLE T2 (ID INTEGER PRIMARY KEY, C2 VARCHAR(255))")
sql = 'INSERT INTO T2 (ID, C2) VALUES (?, ?)'
cursor.executemany(sql, ((1, 'hello'), (2, 'hello again'), (3, 'goodbye' ))
cursor.close()

Use the following example to fetch all of the rows at once from the created table:

sql = "SELECT * FROM T2"
cursor = conn.cursor()
cursor.execute(sql)
rows = cursor.fetchall()
print(rows)
# prints [(1, 'hello'), (2, 'hello again'), (3, 'goodbye')]