MOVE

An SQL command for moving a cursor

MOVE is a DML command for moving a cursor within the cursor's query without retrieving any data.

MOVE has always been present in PostgreSQL.

Change history

MOVE has been present in every PostgreSQL version.

Examples

Basic usage example for MOVE:

postgres=# CREATE TABLE foo (
             id INT NOT NULL PRIMARY KEY,
             val TEXT
           );
CREATE TABLE

postgres=# INSERT INTO foo VALUES (generate_series(1,100));
INSERT 0 100

postgres=# BEGIN;
BEGIN

postgres=*# DECLARE foo_cursor CURSOR
                FOR SELECT id FROM foo ORDER BY 1;
DECLARE CURSOR

postgres=*# FETCH 1 FROM foo_cursor;
 id
----
  1
(1 row)

postgres=*# MOVE NEXT IN foo_cursor;
MOVE 1

postgres=*# FETCH 1 FROM foo_cursor;
 id
----
  3
(1 row)
  • PostgreSQL documentation: MOVE

Categories

Cursors, SQL command

See also

CLOSE, DECLARE, FETCH