Positions a cursor.

Synopsis

  1. MOVE [ <forward_direction> [ FROM | IN ] ] <cursor_name>

where forward_direction can be empty or one of:

  1. NEXT
  2. FIRST
  3. LAST
  4. ABSOLUTE <count>
  5. RELATIVE <count>
  6. <count>
  7. ALL
  8. FORWARD
  9. FORWARD <count>
  10. FORWARD ALL

Description

MOVE repositions a cursor without retrieving any data. MOVE works exactly like the FETCH command, except it only positions the cursor and does not return rows.

Note

You cannot MOVE a PARALLEL RETRIEVE CURSOR.

It is not possible to move a cursor position backwards in Greenplum Database, since scrollable cursors are not supported. You can only move a cursor forward in position using MOVE.

Outputs

On successful completion, a MOVE command returns a command tag of the form

  1. MOVE <count>

The count is the number of rows that a FETCH command with the same parameters would have returned (possibly zero).

Parameters

forward_direction

The parameters for the MOVE command are identical to those of the FETCH command; refer to FETCH for details on syntax and usage.

cursor_name

The name of an open cursor.

Examples

– Start the transaction:

  1. BEGIN;

– Set up a cursor:

  1. DECLARE mycursor CURSOR FOR SELECT * FROM films;

– Move forward 5 rows in the cursor mycursor:

  1. MOVE FORWARD 5 IN mycursor;
  2. MOVE 5

– Fetch the next row after that (row 6):

  1. FETCH 1 FROM mycursor;
  2. code | title | did | date_prod | kind | len
  3. -------+--------+-----+------------+--------+-------
  4. P_303 | 48 Hrs | 103 | 1982-10-22 | Action | 01:37
  5. (1 row)

– Close the cursor and end the transaction:

  1. CLOSE mycursor;
  2. COMMIT;

Compatibility

There is no MOVE statement in the SQL standard.

See Also

DECLARE, FETCH, CLOSE

Parent topic: SQL Commands