BEGIN;

CREATE OR REPLACE FUNCTION nexttime()
RETURNS SETOF timestamp
AS $body$
DECLARE
    i int;
BEGIN
    FOR i IN 1..10 LOOP
	RETURN NEXT timeofday();
    END LOOP;

    RETURN;
END;
$body$
LANGUAGE plpgsql
VOLATILE
ROWS 1;

DECLARE next_time CURSOR FOR SELECT * FROM nexttime();

FETCH next FROM next_time;
\prompt 'Next?' temp
SELECT timeofday();
FETCH next FROM next_time;
\prompt 'Next?' temp
SELECT timeofday();
FETCH next FROM next_time;

ROLLBACK;
