Materialize Documentation
Join the Community github/materialize

FETCH

FETCH retrieves rows from a query using a cursor previously opened with DECLARE.

Syntax

FETCH FORWARD ALL count FROM cursor_name WITH ( option_name = option_value , )
Field Use
count The number of rows to retrieve. Defaults to 1 if unspecified.
cursor_name The name of an open cursor.

WITH option

The following option is valid within the WITH clause.

Option name Value type Default Describes
timeout interval None When fetching from a SUBSCRIBE cursor, complete if there are no more rows ready after this timeout. The default will cause FETCH to wait for at least one row to be available.

Details

FETCH will return at most the specified count of available rows. Specifying a count of ALL indicates that there is no limit on the number of rows to be returned.

For SUBSCRIBE queries, FETCH by default will wait for rows to be available before returning. Specifying a timeout of 0s returns only rows that are immediately available.