How to fix set-valued function called in context that cannot accept a set in earlier versions - Mailing list pgsql-general

From Andrus
Subject How to fix set-valued function called in context that cannot accept a set in earlier versions
Date
Msg-id 4336A43AB8A446CEBAF7AFBD2D050292@andrusnotebook
Whole thread Raw
Responses Re: How to fix set-valued function called in context that cannot accept a set in earlier versions  (hubert depesz lubaczewski <depesz@depesz.com>)
Re: How to fix set-valued function called in context that cannot accept a set in earlier versions  (Kenichiro Tanaka <ketanaka@ashisuto.co.jp>)
List pgsql-general
In 8.3 code below causes exception

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

How to fix this so that wordwrap works in any PostgreSql 8.x version or at
least in
8.3 and 8.4 ?

Andrus

CREATE OR REPLACE FUNCTION wordwrap(line text, linelen integer)
RETURNS SETOF text as $$
DECLARE
  words text[] := string_to_array(line,' ');
  i integer;
  res text:='';

BEGIN
  if trim(line)='' then
    return next '';
    return;
    end if;
 for i IN 1 .. array_upper(words,1) LOOP
   if length(res)+length(words[i]) > linelen THEN
     return next res;
     res := '';
     END IF ;
   if res<>'' then
     res := res || ' ';
     end if;
   res := res || words[i];
   end loop;
return next res;
END
 $$ LANGUAGE plpgsql;

select wordwrap('fdgdf',10)


pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Uninstalling the pl/pgsql debugger
Next
From: hubert depesz lubaczewski
Date:
Subject: Re: How to fix set-valued function called in context that cannot accept a set in earlier versions