Re: [GENERAL] string_to_array with empty input
От | David E. Wheeler |
---|---|
Тема | Re: [GENERAL] string_to_array with empty input |
Дата | |
Msg-id | 69813E76-A2B1-452B-B5B0-F0B2BC708A64@kineticode.com обсуждение исходный текст |
Ответ на | Re: [GENERAL] string_to_array with empty input (Sam Mason <sam@samason.me.uk>) |
Список | pgsql-hackers |
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
В списке pgsql-hackers по дате отправления: