for i in loop returns setof int

Hallo *,

kann mir jemand bei folgender Funktion helfen:

CREATE OR REPLACE FUNCTION ten_integers()
RETURNS SETOF int AS $$
BEGIN
FOR i IN 0…10 LOOP

RETURN NEXT i;
END LOOP;
return;
END;
$$ LANGUAGE plpgsql;

ERROR: set-valued function called in context that cannot accept a set
CONTEXT: PL/pgSQL function “ten_integers” line 5 at RETURN NEXT
STATEMENT: select ten_integers()

Have fun, Stefan :slight_smile:

select * from ten_integers();

Geht vieeeel einfacher:

test=# select * from generate_Series(0,10) as i;
 i
----
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
(11 rows)

Andreas