Cursor
A database cursor is an object or interface that executes database operations and incrementally retrieves or traverses their result rows.
A Pythonic Adventure: From Python basics to a working web app
A database cursor is an object that executes database statements and retrieves their results.
- How it is used
- Uses a cursor to execute SQL commands while connecting a Flask application to a SQLite orders database.
- How deep it goes
- Defines the cursor through an analogy and demonstrates creation and execution, while explicitly deferring deeper details.
- Examples
- Demonstrates CREATE TABLE, INSERT orders, and SELECT-based retrieval in an order-tracking application.
- What you can do after
- Operate/configure a cursor to execute table-creation, insertion, and selection commands in a SQLite-backed Flask application.
Read how A Pythonic Adventure: From Python basics to a working web app explains cursor →
Learn SQL in a Month of Lunches
A database cursor is a database programming construct that enables query-result data to be processed one row at a time.
- How it is used
- Processes SELECT results one row at a time when individual evaluation or per-row procedure calls are required.
- How deep it goes
- Explains the DECLARE, OPEN, FETCH, and CLOSE lifecycle through a complete stored-procedure loop and end-of-results handler.
- Examples
- Uses order IDs to total quantities sold at list price and scenarios involving California orders, first orders, and customer messages.
- What you can do after
- Evaluate/understand cursor-based stored procedures and decide when a set-based query can replace row-by-row processing.
Practices of the Python Pro
A database cursor is an object that executes database statements and provides access to their results.
- How it is used
- Executes SQL statements and exposes query results within a reusable persistence-layer helper.
- How deep it goes
- Defines cursor behavior, demonstrates execution and transactions, and stops short of explaining cursor internals.
- Examples
- Uses a DatabaseManager._execute method to run parameterized SQL through a cursor.
- What you can do after
- Build reusable SQLite statement execution that returns query results and supports parameter values.
Coding with AI
A database cursor is an object that executes database statements and accesses their results through an established connection.
- How it is used
- Uses cursors to connect Flask route handlers and model methods to SQLite queries and returned page data.
- How deep it goes
- Explains cursor creation, query use, dependency passing, and connection cleanup, but stops short of database-driver internals.
- Examples
- Demonstrates selecting records, fetching questions, rendering results, generating question sets, and correcting cursor-related import and constructor errors.
- What you can do after
- Operate/configure database-backed Flask code by passing a live cursor into models, fetching records, and closing connections safely.
API Design Patterns
A cursor is a position marker that identifies the point from which the next portion of paged data should be retrieved.
- How it is used
- Guides consumers through collection pages or chunks of a large resource.
- How deep it goes
- Defines termination, opacity, empty-page behavior, and large-resource continuation, without specifying one token representation.
- Examples
- Uses multi-page resource retrieval, empty-result responses, and chunked attachment reads.
- What you can do after
- Operate pagination by passing returned tokens and stopping only when the next token is empty.
MongoDB 8.0 in Action, Third Edition
A cursor is an object representing an incremental result set from a database query and providing methods for traversing its documents.
- How it is used
- Handles large query results through incremental, batched retrieval and supports automatic or manually controlled document traversal.
- How deep it goes
- Explains cursor creation, batching, lazy loading, automatic display, manual iteration, and read timeouts without detailing driver internals.
- Examples
- Uses routes queries, mongosh display behavior, manualIteration(), and a sample_mflix change-stream cursor.
- What you can do after
- Apply it via mongosh to retrieve query results incrementally, choose manual traversal, and monitor change-stream events.
Read how MongoDB 8.0 in Action, Third Edition explains cursor →
Python Concurrency with asyncio
A database cursor is an object that traverses and retrieves rows from a database query result, potentially incrementally.
- How it is used
- Streams large PostgreSQL query results when pagination or full-result loading creates memory, query, or database-load concerns.
- How deep it goes
- Explains pointer-style traversal, asynchronous iteration, prefetching, skipping, and batching, but not cursor internals.
- Examples
- Uses a product query to stream 1,000 rows, skip 500 rows, fetch 100, or print the first five.
- What you can do after
- Operate/configure asyncpg cursors inside transactions to stream, skip, batch, and limit retrieved rows.
Related concepts
- closehas part · Close is an operation that terminates access to an associated resource or interface and releases or finalizes related resources or pending work.
- find()produced by · find() is a MongoDB Query API method that returns a cursor for documents matching an optional query filter in a collection.
- loopuses · A loop is a programming control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
- stored procedureused by · A stored procedure is a named executable routine stored in and invoked by a database management system to perform database operations.
- SQLuses · SQL is a standardized declarative language for defining, querying, and manipulating data and structures in relational database systems.
- database result setuses · A database result set is the collection of rows and values produced by evaluating a database query.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.






