11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/ref/fetch.sgml,v 1.22 2002/12/30 15:31:47 momjian Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/fetch.sgml,v 1.23 2003/01/08 00:22:26 tgl Exp $
33PostgreSQL documentation
44-->
55
@@ -22,7 +22,7 @@ PostgreSQL documentation
2222 </refsynopsisdivinfo>
2323 <synopsis>
2424FETCH [ <replaceable class="PARAMETER">direction</replaceable> ] [ <replaceable class="PARAMETER">count</replaceable> ] { IN | FROM } <replaceable class="PARAMETER">cursor</replaceable>
25- FETCH [ FORWARD | BACKWARD | RELATIVE ] [ <replaceable class="PARAMETER">#</replaceable> | ALL | NEXT | PRIOR ]
25+ FETCH [ FORWARD | BACKWARD | RELATIVE ] [ <replaceable class="PARAMETER">#</replaceable> | ALL | LAST | NEXT | PRIOR ]
2626 { IN | FROM } <replaceable class="PARAMETER">cursor</replaceable>
2727 </synopsis>
2828
@@ -40,7 +40,7 @@ FETCH [ FORWARD | BACKWARD | RELATIVE ] [ <replaceable class="PARAMETER">#</repl
4040 <term><replaceable class="PARAMETER">direction</replaceable></term>
4141 <listitem>
4242 <para>
43- <replaceable class="PARAMETER">selector </replaceable>
43+ <replaceable class="PARAMETER">direction </replaceable>
4444 defines the fetch direction. It can be one of
4545 the following:
4646
@@ -50,7 +50,7 @@ FETCH [ FORWARD | BACKWARD | RELATIVE ] [ <replaceable class="PARAMETER">#</repl
5050 <listitem>
5151 <para>
5252 fetch next row(s). This is the default
53- if <replaceable class="PARAMETER">selector </replaceable> is omitted.
53+ if <replaceable class="PARAMETER">direction </replaceable> is omitted.
5454 </para>
5555 </listitem>
5656 </varlistentry>
@@ -87,9 +87,9 @@ FETCH [ FORWARD | BACKWARD | RELATIVE ] [ <replaceable class="PARAMETER">#</repl
8787 <term><replaceable class="PARAMETER">#</replaceable></term>
8888 <listitem>
8989 <para>
90- A signed integer that specifies how many rows to fetch.
90+ A signed integer constant that specifies how many rows to fetch.
9191 Note that a negative integer is equivalent to changing the sense of
92- FORWARD and BACKWARD. Zero re-fetches the current row.
92+ FORWARD and BACKWARD. Zero re-fetches the current row, if any .
9393 </para>
9494 </listitem>
9595 </varlistentry>
@@ -105,6 +105,17 @@ FETCH [ FORWARD | BACKWARD | RELATIVE ] [ <replaceable class="PARAMETER">#</repl
105105 </listitem>
106106 </varlistentry>
107107
108+ <varlistentry>
109+ <term>
110+ LAST
111+ </term>
112+ <listitem>
113+ <para>
114+ Same as <literal>ALL</>, but conforms to SQL92 syntax.
115+ </para>
116+ </listitem>
117+ </varlistentry>
118+
108119 <varlistentry>
109120 <term>
110121 NEXT
@@ -151,7 +162,8 @@ FETCH [ FORWARD | BACKWARD | RELATIVE ] [ <replaceable class="PARAMETER">#</repl
151162 Outputs
152163 </title>
153164 <para>
154- <command>FETCH</command> returns the results of the query defined by the specified cursor.
165+ <command>FETCH</command> returns rows from the result of the query defined
166+ by the specified cursor.
155167 The following messages will be returned if the query fails:
156168
157169 <variablelist>
@@ -200,10 +212,33 @@ WARNING: FETCH/ABSOLUTE not supported, using RELATIVE
200212 If the number of rows remaining in the cursor is less
201213 than <replaceable class="PARAMETER">#</replaceable>,
202214 then only those available are fetched.
203- Substituting the keyword ALL in place of a number will
215+ Substituting the keyword ALL or LAST in place of a number will
204216 cause all remaining rows in the cursor to be retrieved.
205- Instances may be fetched in both FORWARD and BACKWARD
217+ Rows may be fetched in both FORWARD and BACKWARD
206218 directions. The default direction is FORWARD.
219+ </para>
220+
221+ <para>
222+ The cursor position can be before the first row of the query result, or on
223+ any particular row of the result, or after the last row of the result.
224+ When created, a cursor is positioned before the first row. After fetching
225+ some rows, the cursor is positioned on the last row retrieved. A new
226+ <command>FETCH</command> always steps one row in the specified direction
227+ (if possible) before beginning to return rows. If the
228+ <command>FETCH</command> requests more rows than available, the cursor is
229+ left positioned after the last row of the query result (or before the first
230+ row, in the case of a backward fetch). This will always be the case after
231+ <command>FETCH ALL</>.
232+ </para>
233+
234+ <tip>
235+ <para>
236+ A zero row count requests fetching the current row without moving the
237+ cursor --- that is, re-fetching the most recently fetched row.
238+ This will succeed unless the cursor is positioned before the
239+ first row or after the last row; in which case, no row is returned.
240+ </para>
241+ </tip>
207242
208243 <tip>
209244 <para>
@@ -213,7 +248,6 @@ WARNING: FETCH/ABSOLUTE not supported, using RELATIVE
213248 <command>FORWARD -1</command> is the same as <command>BACKWARD 1</command>.
214249 </para>
215250 </tip>
216- </para>
217251
218252 <refsect2 id="R2-SQL-FETCH-3">
219253 <refsect2info>
@@ -224,11 +258,9 @@ WARNING: FETCH/ABSOLUTE not supported, using RELATIVE
224258 </title>
225259
226260 <para>
227- Note that the FORWARD and BACKWARD keywords are
261+ Note that the FORWARD, BACKWARD, and ALL keywords are
228262 <productname>PostgreSQL</productname> extensions.
229- The <acronym>SQL92</acronym> syntax is also supported, specified
230- in the second form of the command. See below for details
231- on compatibility issues.
263+ See below for details on compatibility issues.
232264 </para>
233265
234266 <para>
@@ -246,11 +278,11 @@ WARNING: FETCH/ABSOLUTE not supported, using RELATIVE
246278 </para>
247279
248280 <para>
281+ <xref linkend="sql-declare" endterm="sql-declare-title">
282+ is used to define a cursor.
249283 Use
250284 <xref linkend="sql-move" endterm="sql-move-title">
251- to change cursor position.
252- <xref linkend="sql-declare" endterm="sql-declare-title">
253- will define a cursor.
285+ to change cursor position without retrieving data.
254286 Refer to
255287 <xref linkend="sql-begin" endterm="sql-begin-title">,
256288 <xref linkend="sql-commit" endterm="sql-commit-title">,
0 commit comments