CLOSE

Name

CLOSE  --  Closes a cursor

Synopsis

CLOSE cursor
  

Inputs

cursor

The name of an open cursor to close.

Outputs

CLOSE

Message returned if the cursor is successfully closed.

NOTICE PerformPortalClose: portal "cursor" not found

This warning is given if cursor is not declared or has already been closed.

Description

CLOSE frees the resources associated with an open cursor. After the cursor is closed, no subsequent operations are allowed on it. A cursor should be closed when it is no longer needed.

An implicit close is executed for every open cursor when a transaction is terminated by COMMIT or ROLLBACK.

Notes

PostgreSQL does not have an explicit OPEN cursor statement; a cursor is considered open when it is declared. Use the DECLARE statement to declare a cursor.

Usage

Closing a cursor:

CREATE TABLE POINT_TBL2(f1 point);
INSERT INTO POINT_TBL2(f1) VALUES ('(0.0,0.0)');
INSERT INTO POINT_TBL2(f1) VALUES ('(-10.0,0.0)');
INSERT INTO POINT_TBL2(f1) VALUES ('(-3.0,4.0)');
INSERT INTO POINT_TBL2(f1) VALUES ('(5.1, 34.5)');
INSERT INTO POINT_TBL2(f1) VALUES ('(-5.0,-12.0)');
INSERT INTO POINT_TBL2(f1) VALUES ('(7.0,-3.0)');
BEGIN WORK;
/* DECLARE the CURSOR */
DECLARE cursor1 CURSOR FOR SELECT * FROM POINT_TBL2;
/* FETCH IN CURSOR */
FETCH FORWARD 3 IN cursor1;
MOVE BACKWARD 5 IN cursor1;
/* CLOSE the CURSOR */
CLOSE cursor1;
COMMIT WORK;

Compatibility

SQL92

CLOSE is fully compatible with SQL92.