469,602 Members | 1,826 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Passing a comma delimited list to a function

A E
Hi,

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.

Did not think it was very efficient to loop through the contents of the list finding delimiters.

TIA
Alex

Nov 12 '05 #1
2 4491
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

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #2
Take a look at:
http://www.postgres.org/docs/current...ns-string.html

The split_part() function should do the trick.

== Ezra Epstein

"A E" <co*******@yahoo.com> wrote in message
news:20************************@web12103.mail.yaho o.com...
Hi,

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.

Did not think it was very efficient to loop through the contents of the list
finding delimiters.

TIA
Alex
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Roy Smith | last post: by
2 posts views Thread by Larry Williams | last post: by
6 posts views Thread by billsahiker | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.