Re: How to fix set-valued function called in context that cannot accept a set in earlier versions

Поиск
Список
Период
Сортировка
От Andrus
Тема Re: How to fix set-valued function called in context that cannot accept a set in earlier versions
Дата
Msg-id DD690FC0EA8B483F93C32D7A349D20FA@andrusnotebook
обсуждение исходный текст
Ответ на Re: How to fix set-valued function called in context that cannot accept a set in earlier versions  (Merlin Moncure <mmoncure@gmail.com>)
Ответы Re: How to fix set-valued function called in context that cannot accept a set in earlier versions  (hubert depesz lubaczewski <depesz@depesz.com>)
Список pgsql-general
Thank you.

> another workaround is to wrap the pl/pgsql function in sql function.
> it's not always easy to re-work the function all into a 'from'
> expression.

I tried code below in 8.3 but got error

ERROR:  syntax error at or near "select"
LINE 30: select * from wordwrap(line,linelen);

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;

CREATE OR REPLACE FUNCTION wordwrap83(line text, linelen integer)
RETURNS SETOF text as $$
BEGIN
select * from wordwrap(line,linelen);
END
 $$ LANGUAGE sql;


select wordwrap83('fdgdf',10)

В списке pgsql-general по дате отправления:

Предыдущее
От: "Igor Neyman"
Дата:
Сообщение: Re: join two tables without a key
Следующее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: How to fix set-valued function called in context that cannot accept a set in earlier versions