From: | Sam Mason <sam(at)samason(dot)me(dot)uk> |
---|---|
To: | pgsql-general(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: string_to_array with empty input |
Date: | 2009-03-31 15:34:01 |
Message-ID: | 20090331153401.GC12225@frubble.xen.chris-lamb.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On Tue, Mar 31, 2009 at 03:43:37PM +0100, Greg Stark wrote:
> 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.
Really? I think it's strange not to!
> 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'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',','))
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.
--
Sam http://samason.me.uk/
From | Date | Subject | |
---|---|---|---|
Next Message | Marcin Krol | 2009-03-31 15:35:58 | weird problem with PG 8.1 |
Previous Message | Tom Lane | 2009-03-31 15:31:18 | Re: [GENERAL] pgstattuple triggered checkpoint failure and database outage? |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-03-31 15:37:16 | Re: [HACKERS] string_to_array with empty input |
Previous Message | Tom Lane | 2009-03-31 15:31:18 | Re: [GENERAL] pgstattuple triggered checkpoint failure and database outage? |