From: Daniele Varrazzo Date: Wed, 10 Feb 2021 01:18:51 +0000 (+0100) Subject: Add docs for Cursor.scroll() X-Git-Tag: 3.0.dev0~115^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1e801026eefb4a922cd16f69a22196ca72ca1cc;p=thirdparty%2Fpsycopg.git Add docs for Cursor.scroll() --- diff --git a/docs/cursor.rst b/docs/cursor.rst index a1f0d9515..1b7f7a012 100644 --- a/docs/cursor.rst +++ b/docs/cursor.rst @@ -127,8 +127,10 @@ The `!Cursor` class .. automethod:: fetchmany .. automethod:: fetchall .. automethod:: nextset + .. automethod:: scroll .. autoattribute:: pgresult + .. rubric:: Information about the data .. attribute:: description @@ -192,6 +194,7 @@ The `!AsyncCursor` class .. automethod:: fetchone .. automethod:: fetchmany .. automethod:: fetchall + .. automethod:: scroll .. note:: You can also use ``async for record in cursor: ...`` to iterate on the async cursor results. diff --git a/psycopg3/psycopg3/cursor.py b/psycopg3/psycopg3/cursor.py index 05cdc6001..b341f03a6 100644 --- a/psycopg3/psycopg3/cursor.py +++ b/psycopg3/psycopg3/cursor.py @@ -570,6 +570,16 @@ class Cursor(BaseCursor["Connection"]): yield row def scroll(self, value: int, mode: str = "relative") -> None: + """ + Move the cursor in the result set to a new position according to mode. + + If *mode* is ``relative`` (default), value is taken as offset to the + current position in the result set, if set to ``absolute``, *value* + states an absolute target position. + + Raise `!IndexError` in case a scroll operation would leave the result + set. In this case the position will not change. + """ self._scroll(value, mode) @contextmanager