Skip to content

FETCH

DECLARE cursor_example CURSOR FOR SELECT * FROM table_sample;
FETCH NEXT FROM cursor_example;
column1 | column2 | column3
--------|---------|--------
1 | a | aaa
2 | b | bbb
3 | c | ccc

The FETCH command in PostgreSQL is used to retrieve rows from a result set one at a time or few at a time. In the example mentioned above, DECLARE cursor is created for columns from table_sample. Then, FETCH command is used to retrieve the next set of rows of the cursor.