DECLARE

DECLARE creates a cursor, which can be used with FETCH, to retrieve a limited number of rows at a time from a larger query. Large queries or queries that don’t ever complete (SUBSCRIBE) can be difficult to use with many PostgreSQL drivers that wait until all rows are returned before returning control to an application. Using DECLARE and FETCH allows you to fetch only some of the rows at a time.

Syntax

DECLARE <cursor_name> CURSOR FOR <query>;
Syntax element Description
<cursor_name> The name of the cursor to be created.
<query> The query (SELECT or SUBSCRIBE) that will provide the rows to be returned by the cursor.
Back to top ↑