On Mar 31, 2009, at 8:34 AM, Sam Mason wrote:
What do you really expect to be returned for things like
select count_elements(string_to_array('butter,tea,milk',','))
3 = {butter,tea,milk}
select count_elements(string_to_array('butter,tea',','))
2 = {butter,tea}
select count_elements(string_to_array('butter',','))
1 = {butter}
select count_elements(string_to_array('',','))
1 = ARRAY['']
I'd expect 3,2,1 and 1.
That's also a disingenuous example; what would you expect back from:
select count_elements(string_to_array('butter,,milk',','))
3 = ARRAY['butter', '', 'milk']
I think the semantics you want is what you'd get from:
array_filter_blanks(string_to_array($1,$2))
where I defined "array_filter_blanks" in my previous post.
Yeah, if I wanted something like that in Perl, I'd do:
my @stuff = grep { $_ } split /,/, $string;
In no case would I ever expect a NULL, however, unless I was trying to
split on NULL.
NULL = string_to_array(NULL, ',');
Best,
David
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general