Re: string_to_array with an empty input string

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Thom Brown <thom(at)linux(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: string_to_array with an empty input string
Date: 2010-08-11 07:12:17
Message-ID: AANLkTimLmEc46Hi0Jt-0-VphnsePbkwzq3mKiNYddwg4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Aug 11, 2010 at 12:37 AM, Peter Geoghegan
<peter(dot)geoghegan86(at)gmail(dot)com> wrote:
> On 10 August 2010 19:48, David E. Wheeler <david(at)kineticode(dot)com> wrote:
>> On Aug 10, 2010, at 11:46 AM, Thom Brown wrote:
>>
>>> I, personally, would expect an empty array output given an empty
>>> input, and a null output for a null input.
>>
>> +1
>
> Agreed. After all, the result isn't indeterminate - it's an empty
> array. Some people might think that it's useful for the result to be
> NULL, but they'd probably also think that it's useful for an empty
> string to be NULL.
>

For what it's worth there are two reasonable return values for
string_to_array(''). It could be [] or it could be ['']. There are
applications where the former makes the most sense and there are
applications where the latter makes the most sense.

Ideally you really want string_to_array(array_to_string(x, ':'),':')
to return x. There's no safe return value to pick for the cases where
x=[''] and x=[] that will make this work.

--
greg

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2010-08-11 07:23:26 Re: string_to_array with an empty input string
Previous Message Peter Eisentraut 2010-08-11 05:31:42 assertions and constraint triggers