of cursor.
1999-07-20
-MOVE [ direction ] [ count ]
+MOVE [ direction ]
+ {count | LAST }
{ IN | FROM } cursor
MOVE allows a user to move cursor position a specified
number of rows.
MOVE works like the FETCH command,
- but only positions the cursor and does
- not return rows.
+ but only positions the cursor and does not return rows.
+ LAST moves to the end
+ of the cursor.
Refer to
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.3 2002/09/04 20:31:15 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.4 2002/11/13 00:44:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
+#include
+
#include "commands/portalcmds.h"
#include "executor/executor.h"
*
* name: name of portal
* forward: forward or backward fetch?
- * count: # of tuples to fetch (0 implies all)
+ * count: # of tuples to fetch
* dest: where to send results
* completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
* in which to store a command completion status string.
return;
}
+ /* If zero count, we are done */
+ if (count == 0)
+ return;
+
+ /* Internally, zero count processes all portal rows */
+ if (count == INT_MAX)
+ count = 0;
+
/*
* switch into the portal context
*/
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.185 2002/11/13 00:39:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.186 2002/11/13 00:44:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*
* check our tuple count.. if we've processed the proper number
- * then quit, else loop again and process more tuples..
+ * then quit, else loop again and process more tuples. Zero
+ * number_tuples means no limit.
*/
current_tuple_count++;
if (numberTuples == current_tuple_count)
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.376 2002/11/11 22:19:23 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.377 2002/11/13 00:44:08 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
#include "postgres.h"
#include
+#include
#include "access/htup.h"
#include "catalog/index.h"
KEY
- LANCOMPILER LANGUAGE LEADING LEFT LEVEL LIKE LIMIT
+ LANCOMPILER LANGUAGE LAST LEADING LEFT LEVEL LIKE LIMIT
LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
LOCK_P
if ($3 < 0)
{
$3 = -$3;
- $2 = (($2 == FORWARD)? BACKWARD: FORWARD);
+ $2 = (($2 == FORWARD) ? BACKWARD: FORWARD);
}
n->direction = $2;
n->howMany = $3;
fetch_how_many:
Iconst { $$ = $1; }
| '-' Iconst { $$ = - $2; }
- /* 0 means fetch all tuples*/
- | ALL { $$ = 0; }
+ | ALL { $$ = INT_MAX; }
+ | LAST { $$ = INT_MAX; }
| NEXT { $$ = 1; }
| PRIOR { $$ = -1; }
;
| KEY
| LANGUAGE
| LANCOMPILER
+ | LAST
| LEVEL
| LISTEN
| LOAD
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.129 2002/11/11 22:19:23 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.130 2002/11/13 00:44:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{"key", KEY},
{"lancompiler", LANCOMPILER},
{"language", LANGUAGE},
+ {"last", LAST},
{"leading", LEADING},
{"left", LEFT},
{"level", LEVEL},
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.180 2002/10/21 20:31:52 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.181 2002/11/13 00:44:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
forward = (bool) (stmt->direction == FORWARD);
/*
- * parser ensures that count is >= 0 and 'fetch ALL' -> 0
+ * parser ensures that count is >= 0
*/
-
count = stmt->howMany;
PerformPortalFetch(portalName, forward, count,
(stmt->ismove) ? None : dest,
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: portalcmds.h,v 1.2 2002/09/04 20:31:42 momjian Exp $
+ * $Id: portalcmds.h,v 1.3 2002/11/13 00:44:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/*
* PerformPortalFetch
- * Performs the POSTQUEL function FETCH. Fetches count (or all if 0)
+ * Performs the POSTQUEL function FETCH. Fetches count
* tuples in portal with name in the forward direction iff goForward.
*
* Exceptions:
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: parsenodes.h,v 1.212 2002/11/11 22:19:24 tgl Exp $
+ * $Id: parsenodes.h,v 1.213 2002/11/13 00:44:09 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
NodeTag type;
int direction; /* FORWARD or BACKWARD */
- int howMany; /* amount to fetch ("ALL" --> 0) */
+ int howMany; /* amount to fetch */
char *portalname; /* name of portal (cursor) */
bool ismove; /* TRUE if MOVE */
} FetchStmt;