CLOSE

An SQL command for closing an open cursor

CLOSE is a utility command for closing an open cursor.

CLOSE has always been present in PostgreSQL.

Change history

CLOSE has been present in every PostgreSQL version.

Examples

Basic usage example for CLOSE:

postgres=# BEGIN;
BEGIN

postgres=*# DECLARE foo_cursor CURSOR
                FOR SELECT * FROM foo;
DECLARE CURSOR

postgres=*# CLOSE foo_cursor;
CLOSE CURSOR

Attempting to close a non-existent cursor:

postgres=*# CLOSE foo_cursor;
ERROR:  cursor "foo_cursor" does not exist

CLOSE ALL succeeds regardless of whether any cursors currently exist:

postgres=*# SELECT * FROM pg_cursors;
 name | statement | is_holdable | is_binary | is_scrollable | creation_time
------+-----------+-------------+-----------+---------------+---------------
(0 rows)

postgres=*# CLOSE ALL;
CLOSE CURSOR ALL
  • PostgreSQL documentation: CLOSE

Categories

Cursors, SQL command

See also

DECLARE, FETCH, MOVE, pg_cursors