From: | Greg Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | Brendan Jurd <direvus(at)gmail(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Steve Crawford <scrawford(at)pinpointresearch(dot)com>, pgsql-general(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: string_to_array with empty input |
Date: | 2009-03-31 14:43:37 |
Message-ID: | 4136ffa0903310743n6ad22f51h91bc0b9616e2ed5d@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On Tue, Mar 31, 2009 at 7:45 AM, Brendan Jurd <direvus(at)gmail(dot)com> wrote:
> My first thought was that it should be a zero-element array, because
> then the string_to_array() behaviour would conform to the notion that
> it returns an array with 1 element per string fragment bounded by the
> delimiter.
>
> However, I note that if you provide an empty delimiter, or one which
> doesn't occur anywhere in the source string, you get an array with one
> element, being the entire source string.
Yeah, actually the more I think about it the more I think it would be
strange for most uses to get a singleton array for this case.
What do you really expect to be returned for things like
select count_elements(string_to_array('butter,tea,milk',','))
select count_elements(string_to_array('butter,tea',','))
select count_elements(string_to_array('butter',','))
select count_elements(string_to_array('',','))
...
I could see lists like this being stored when people gather data using
a web form or something and don't want to bother normalizing some
trivial bit of data collection which they'll never individually, but
have to unnest the list for some display purposes.
The cases where it makes more sense to return a singleton array are
going to be parsing things like /etc/password where there are specific
meanings for each element, but when some are optional. I can't think
of any examples offhand though.
--
greg
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Stark | 2009-03-31 14:44:49 | Re: string_to_array with empty input |
Previous Message | Sam Mason | 2009-03-31 14:42:56 | Re: [HACKERS] string_to_array with empty input |
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Stark | 2009-03-31 14:44:49 | Re: string_to_array with empty input |
Previous Message | Sam Mason | 2009-03-31 14:42:56 | Re: [HACKERS] string_to_array with empty input |