On this page
sqlite3.Row
Prev: sqlite3.register_converter | Up: sqlite3 | Next: sqlite3.Time
Rel: sqlite3.adapt, sqlite3.Binary, sqlite3.Blob, sqlite3.complete_statement
Ref: docs.python.org — sqlite3.Row
Tags: #public #python3 #stdlib #sqlite3
Import
import sqlite3
from sqlite3 import Row
Signature & Overview
sqlite3.Row(...)
sqlite3.Row class.
Methods & Attributes
Row.keys(self, /)— Returns the keys of the row.
Usage
import sqlite3
con = sqlite3.connect(":memory:")
con.row_factory = sqlite3.Row
row = con.execute("SELECT 1 AS id, 'Ada' AS name").fetchone()
assert row["name"] == "Ada" and row[0] == 1 and dict(row) == {"id": 1, "name": "Ada"}
con.close()
Gotchas
- Supports both column-name and index access: Much more readable than raw tuples, with minimal overhead, and converts cleanly via
dict(row). - Case-insensitive column keys:
row["NAME"]androw["name"]both work.
REPL Inspect
from sqlite3 import Row
help(Row)
Linked from
Related notes
- tuts/python3/stdlib_module/sqlite3 Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/register_converter Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Time Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/adapt Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Binary Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/Blob Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/sqlite3/complete_statement Linked here; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib