Re: Passing a comma delimited list to a function

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: Passing a comma delimited list to a function
Дата
Msg-id 3FF74BD3.1030302@joeconway.com
обсуждение исходный текст
Ответ на Passing a comma delimited list to a function  (A E <cooljoint@yahoo.com>)
Список pgsql-general
A E wrote:
> I was wondering if there was a function that handles list elements of
> a comma delimited list? I need to be able to pass values as a comma
> delimited list, count the number of values, and process the value of
> each.

You didn't mention a version, but in 7.4 you can do this:

create or replace function unravel(text) returns setof int as '
declare
  v_list alias for $1;
  v_delim text := '','';
  v_arr text[];
begin
  v_arr := string_to_array(v_list, v_delim);
  for i in array_lower(v_arr, 1)..array_upper(v_arr, 1) loop
    return next v_arr[i]::int;
  end loop;
  return;
end;
' language plpgsql;

regression=# select * from unravel('1,2,3,4,5');
  unravel
---------
        1
        2
        3
        4
        5
(5 rows)

HTH,

Joe



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

Предыдущее
От: Rory Campbell-Lange
Дата:
Сообщение: Re: Is my MySQL Gaining ?
Следующее
От: "Marc G. Fournier"
Дата:
Сообщение: Network Problems over past 48hrs