MOVE is a cursor-control command in PostgreSQL that shifts the cursor’s position within its result set but does not return the moved-over rows to the client. It shares the same direction options as FETCH (NEXT, PRIOR, FIRST, LAST, ABSOLUTE n, RELATIVE n, FORWARD/BACKWARD [count|ALL]). Because no data are transmitted, MOVE is faster than FETCH when the application only needs to reposition the cursor. MOVE can be issued inside explicit transactions or PL/pgSQL code that has an open cursor. Attempting to MOVE a non-existent cursor, or moving beyond the available rows, raises a warning but not an error. MOVE respects the SCROLL attribute declared on the cursor; non-scrollable cursors can only MOVE FORWARD.
direction
(optional) - keyword - Specifies how many rows and in which direction to move. Valid values: NEXT, PRIOR, FIRST, LAST, ABSOLUTE count, RELATIVE count, FORWARD/BACKWARD [count|ALL]FROM | IN
(optional) - keyword - Noise words accepted for SQL conformancecursor_name
(identifier) - The name of an open cursorFETCH, DECLARE CURSOR, CLOSE, SCROLL, FORWARD, BACKWARD, ABSOLUTE, RELATIVE
PostgreSQL 7.3
MOVE repositions the cursor and returns only a row count, while FETCH repositions the cursor and returns the actual row data that were skipped or reached.
No. Cursors exist only within an open transaction block. Issue BEGIN first, then DECLARE, MOVE, FETCH, and CLOSE before COMMIT/ROLLBACK.
Use syntax like `MOVE ABSOLUTE 500 IN my_cur;` to set the cursor right before the 500th row in the result set.
PostgreSQL moves the cursor to the end and returns a count of 0, indicating no rows were skipped beyond the boundary.