array function problem - Mailing list pgsql-general

From tuanhoanganh
Subject array function problem
Date
Msg-id c235f61d0803162137g2c0a0efdq31b1d08f6e08ace0@mail.gmail.com
Whole thread Raw
Responses Re: array function problem
List pgsql-general
I have a array function
CREATE OR REPLACE FUNCTION "temp".rowfromarray(text[])
  RETURNS SETOF text AS
$BODY$DECLARE
    _return    text;
BEGIN
    for i in 1..array_upper($1,1) loop
        _return := $1[i];
        return next _return;
    end loop;
    return;
END;$BODY$
  LANGUAGE 'plpgsql' VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION "temp".rowfromarray(text[]) OWNER TO postgres;

I call it by command
select temp.rowfromarray(string_to_array('1,2,3,4,5', ','));
but it have error

ERROR:  set-valued function called in context that cannot accept a set
CONTEXT:  PL/pgSQL function "rowfromarray" line 6 at RETURN NEXT

********** Error **********

ERROR: set-valued function called in context that cannot accept a set
SQL state: 0A000
Context: PL/pgSQL function "rowfromarray" line 6 at RETURN NEXT

When i debug it by pass {1,2,3,4,5} to first parameter, it run well.

Please help me.
Thanks you very much. Sorry for my English.

pgsql-general by date:

Previous
From: "Harvey, Allan AC"
Date:
Subject: Re: Updating
Next
From: Tom Lane
Date:
Subject: Re: array function problem