Skip to content

DECLARE

Create a cursor within a transaction block.

DECLARE name CURSOR  [ { WITH | WITHOUT } HOLD ] FOR query

See also CLOSE, FETCH, and MOVE (related cursor commands).

WITH HOLD | WITHOUT HOLD
WITH HOLD specifies that a cursor can continue to be used after the transaction in which it was created commits. WITHOUT HOLD, the default, specifies that the cursor cannot be used outside of the transaction that created it.

The DECLARE command must be used within a transaction block. For example:

premdb=# begin;
BEGIN
premdb=# declare match cursor for select * from match order by matchday;
DECLARE CURSOR
...

Parent topic:SQL Commands