473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 4680
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Roy Smith | last post by:
I've got a silly little problem that I'm solving in C++, but I got to thinking about how much easier it would be in Python. Here's the problem: You've got a list of words (actually, they're...
1
by: ouioui | last post by:
Hi, I need to use the xsl sum function like that : <xsl:value-of select="sum(CompteRendu/Compte/@number)" /> My xml source contains number with comma like that : <Compte number=447,68" ...
4
by: Christine Forber | last post by:
I wonder if anyone knows of some javascript code to check a comma-delimited list of email addresses for basic formating. What I'm looking for is the javascript code to check a form field on form...
2
by: Larry Williams | last post by:
Is there an easy way to convert a string of data to XML format without having to create the xml one field at a time? Sorry I'm a newbie and my xml knowledge is limited. I have tried to search...
22
by: argniw | last post by:
I have a table that looks like this: Forest Residents Black Josh Black Joellen Black Mary Jane Brown Gertrude Brown Josh Brown Mary Jane
3
by: Crazy Cat | last post by:
I've created a TableAdapter which implements the following SQL statement SELECT MSC.MSC_NAME AS NAME, Capacity.Capacity AS CAPACITY FROM Capacity INNER JOIN MSC ON Capacity.MSC_KEY =...
5
by: moni | last post by:
Hi.. I am trying to use javascript for google maps display. If I call the javascript function from my aspx file I use: <input type="text" id="addresstext" value="Huntington Avenue,...
6
by: billsahiker | last post by:
I cannot get anything to validate a comma delimited list of stock symbols, like "IBM, MSFT,INTC). symbols are alphanumeric with a maxium length of 5. I want to block multiple, adjacent commas, and...
2
by: Jim | last post by:
Hello: I have a variable which contains a comma delimited list contained in a database variable e.g. "5,6,9,10,55,42" - I want to hand this list to an array function to get it to populate an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.