Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] string_to_array with empty input

From: Brendan Jurd <direvus(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Steve Crawford <scrawford(at)pinpointresearch(dot)com>, pgsql-general(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] string_to_array with empty input
Date: 2009-03-31 06:45:33
Message-ID: 37ed240d0903302345u4dc2fa04id539d1b62046b922@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-hackers
On Tue, Mar 31, 2009 at 2:26 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Does anyone want to argue for keeping it the same?  Or perhaps
> argue that a zero-element array is a more sensible result than
> a one-element array with one empty string?  (It doesn't seem
> like it to me, but maybe somebody thinks so.)
>

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.

# select string_to_array('1-2-3', '-');
 {1,2,3}

# select string_to_array('1-2-3', 'x');
 {1-2-3}

Given this behaviour, I would argue for consistent treatment for a
zero-length source string: it should return an array with one element,
being the entire source string, whenever there is no string splitting
to take place.  And if the source string happens to be zero-length,
then the return value would be as expected by the OP.

Cheers,
BJ

In response to

Responses

pgsql-hackers by date

Next:From: Heikki LinnakangasDate: 2009-03-31 07:20:36
Subject: Re: Re: [GENERAL] pgstattuple triggered checkpoint failure and database outage?
Previous:From: Greg StarkDate: 2009-03-31 06:16:05
Subject: Re: string_to_array with empty input

pgsql-general by date

Next:From: Heikki LinnakangasDate: 2009-03-31 07:20:36
Subject: Re: Re: [GENERAL] pgstattuple triggered checkpoint failure and database outage?
Previous:From: Greg StarkDate: 2009-03-31 06:16:05
Subject: Re: string_to_array with empty input

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group